home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / Drtf / DDrawPICT.cpp < prev    next >
Text File  |  1996-07-05  |  62KB  |  2,413 lines

  1. // DDrawPICT.cpp
  2. //  translate Mac QuickDraw PICT data format to NCBI Draw methods 
  3.  
  4.  
  5. // debugging -- file list
  6. #undef PLIST
  7.  
  8. #include <ncbi.h>
  9. #include <ncbidraw.h>
  10. #include <ncbiwin.h>
  11. #include <ncbiport.h>
  12. #include <vibtypes.h>
  13. #include <vibincld.h>
  14.  
  15. // avoid mess with document.h
  16. #define _DOCUMENT_
  17.  
  18. #include "Dvibrant.h"
  19. #include "DDrawPICT.h"
  20.  
  21. #ifdef WIN_MAC
  22. #include <Palettes.h>
  23. #endif
  24.  
  25. #define byte             unsigned char
  26. #define word             unsigned short
  27. #define longword     unsigned long
  28.  
  29.  
  30. #ifdef PLIST
  31. FILE* gPlist= NULL;
  32. Boolean gDoPlist = true;
  33. #endif
  34.  
  35.  
  36.  
  37. enum PICTops {
  38.     oNOP =    0,
  39.     oClip,
  40.     oBkPat,
  41.     oTxFont,
  42.     oTxFace,
  43.     oTxMode,
  44.     oSpExtra,
  45.     oPnSize,
  46.     oPnMode,
  47.     oPnPat,
  48.     oFillPat,
  49.     oOvSize,
  50.     oOrigin,
  51.     oTxSize,
  52.     oFgColor,
  53.     oBkColor,
  54.     oTxRatio,
  55.     oVersion,
  56.     oBkPixPat,
  57.     oPnPixPat,
  58.     oFillPixPat,
  59.     oPnLocHFrac,
  60.     oChExtra,
  61.     r17,r18,r19,
  62.     oRGBFgCol    = 0x1a,
  63.     oRGBBkCol,
  64.     oHiliteMode,
  65.     oHiliteColor,
  66.     oDefHilite,
  67.     oOpColor,
  68.     oLine,
  69.     oLineFrom,
  70.     oShortLine,
  71.     oShortLineFrom,
  72.     r24,r25,r26,r27,
  73.     oLongText    = 0x28,
  74.     oDHText,
  75.     oDVText,
  76.     oDHDVText,
  77.     oFontName, /* was res2c */
  78.     r2d,
  79.     or2e_mov,  /* was res2e -- just a GUESS !!! */
  80.     r2f,
  81.     oframeRect    = 0x30,
  82.     opaintRect,
  83.     oeraseRect,
  84.     oinvertRect,
  85.     ofillRect,
  86.     r35,r36,r37,
  87.     oframeSameRect = 0x38,
  88.     opaintSameRect,
  89.     oeraseSameRect,
  90.     oinvertSameRect,
  91.     ofillSameRect,
  92.     r3d,r3e,r3f,
  93.     oframeRRect     = 0x40,
  94.     opaintRRect,
  95.     oeraseRRect,
  96.     oinvertRRect,
  97.     ofillRRect,
  98.     r45,r46,r47,
  99.     oframeSameRRect    = 0x48,
  100.     opaintSameRRect,
  101.     oeraseSameRRect,
  102.     oinvertSameRRect,
  103.     ofillSameRRect,
  104.     r4d,r4e,r4f,
  105.     oframeOval = 0x50,
  106.     opaintOval,
  107.     oeraseOval,
  108.     oinvertOval,
  109.     ofillOval,
  110.     r55,r56,r57,
  111.     oframeSameOval = 0x58,
  112.     opaintSameOval,
  113.     oeraseSameOval,
  114.     oinvertSameOval,
  115.     ofillSameOval,
  116.     r5d,r5e,r5f,
  117.     oframeArc = 0x60,
  118.     opaintArc,
  119.     oeraseArc,
  120.     oinvertArc,
  121.     ofillArc,
  122.     r65,r66,r67,
  123.     oframeSameArc = 0x68,
  124.     opaintSameArc,
  125.     oeraseSameArc,
  126.     oinvertSameArc,
  127.     ofillSameArc,
  128.     r6d,r6e,r6f,
  129.     oframePoly = 0x70,
  130.     opaintPoly ,
  131.     oerasePoly,
  132.     oinvertPoly,
  133.     ofillPoly,
  134.     r75,r76,r77,
  135.     oframeSamePoly = 0x78,
  136.     opaintSamePoly,
  137.     oeraseSamePoly,
  138.     oinvertSamePoly,
  139.     ofillSamePoly,
  140.     r7d,r7e,r7f,
  141.     oframeRgn = 0x80,
  142.     opaintRgn,
  143.     oeraseRgn,
  144.     oinvertRgn,
  145.     ofillRgn,
  146.     r85,r86,r87,
  147.     oframeSameRgn = 0x88,
  148.     opaintSameRgn,
  149.     oeraseSameRgn,
  150.     oinvertSameRgn,
  151.     ofillSameRgn,
  152.     r8d,r8e,r8f,
  153.     oBitsRect = 0x90,
  154.     oBitsRgn,
  155.     r92,r93,r94,r95,r96,r97,
  156.     oPackBitsRect = 0x98,
  157.     oPackBitsRgn,
  158.     oOpcode9A,
  159.     r9b,r9c,r9d,r9e,r9f,
  160.     oShortComment = 0xa0,
  161.     oLongComment,
  162.     /* a2..af,b0..fe unused */
  163.     oopEndPic    = 0x00ff,
  164.     /* 0100..ffff unused */
  165.     oHeaderOp    = 0x0c00
  166.     };
  167.     
  168.  
  169. #ifdef PLIST
  170. static char* gOpnames[] = {
  171.  "oNOP",
  172.  "oClip",
  173.  "oBkPat",
  174.  "oTxFont",
  175.  "oTxFace",
  176.  "oTxMode",
  177.  "oSpExtra",
  178.  "oPnSize",
  179.  "oPnMode",
  180.  "oPnPat",
  181.  "oFillPat",
  182.  "oOvSize",
  183.  "oOrigin",
  184.  "oTxSize",
  185.  "oFgColor",
  186.  "oBkColor",
  187.  "oTxRatio",
  188.  "oVersion",
  189.  "oBkPixPat",
  190.  "oPnPixPat",
  191.  "oFillPixPat",
  192.  "oPnLocHFrac",
  193.  "oChExtra",
  194.  "r17","r18","r19",
  195.  "oRGBFgCol",
  196.  "oRGBBkCol",
  197.  "oHiliteMode",
  198.  "oHiliteColor",
  199.  "oDefHilite",
  200.  "oOpColor",
  201.  "oLine",
  202.  "oLineFrom",
  203.  "oShortLine",
  204.  "oShortLineFrom",
  205.     "r24","r25","r26","r27",
  206.  "oLongText",
  207.  "oDHText",
  208.  "oDVText",
  209.  "oDHDVText",
  210.  "oFontName",  
  211.     "r2d",
  212.  "or2e_mov", 
  213.     "r2f",
  214.  "oframeRect",
  215.  "opaintRect",
  216.  "oeraseRect",
  217.  "oinvertRect",
  218.  "ofillRect",
  219.     "r35","r36","r37",
  220.  "oframeSameRect",
  221.  "opaintSameRect",
  222.  "oeraseSameRect",
  223.  "oinvertSameRect",
  224.  "ofillSameRect",
  225.     "r3d","r3e","r3f",
  226.  "oframeRRect",
  227.  "opaintRRect",
  228.  "oeraseRRect",
  229.  "oinvertRRect",
  230.  "ofillRRect",
  231.     "r45","r46","r47",
  232.  "oframeSameRRect",
  233.  "opaintSameRRect",
  234.  "oeraseSameRRect",
  235.  "oinvertSameRRect",
  236.  "ofillSameRRect",
  237.     "r4d","r4e","r4f",
  238.  "oframeOval",
  239.  "opaintOval",
  240.  "oeraseOval",
  241.  "oinvertOval",
  242.  "ofillOval",
  243.     "r55","r56","r57",
  244.  "oframeSameOval",
  245.  "opaintSameOval",
  246.  "oeraseSameOval",
  247.  "oinvertSameOval",
  248.  "ofillSameOval",
  249.     "r5d","r5e","r5f",
  250.  "oframeArc",
  251.  "opaintArc",
  252.  "oeraseArc",
  253.  "oinvertArc",
  254.  "ofillArc",
  255.     "r65","r66","r67",
  256.  "oframeSameArc",
  257.  "opaintSameArc",
  258.  "oeraseSameArc",
  259.  "oinvertSameArc",
  260.  "ofillSameArc",
  261.     "r6d","r6e","r6f",
  262.  "oframePoly",
  263.  "opaintPoly",
  264.  "oerasePoly",
  265.  "oinvertPoly",
  266.  "ofillPoly",
  267.     "r75","r76","r77",
  268.  "oframeSamePoly",
  269.  "opaintSamePoly",
  270.  "oeraseSamePoly",
  271.  "oinvertSamePoly",
  272.  "ofillSamePoly",
  273.     "r7d","r7e","r7f",
  274.  "oframeRgn",
  275.  "opaintRgn",
  276.  "oeraseRgn",
  277.  "oinvertRgn",
  278.  "ofillRgn",
  279.     "r85","r86","r87",
  280.  "oframeSameRgn",
  281.  "opaintSameRgn",
  282.  "oeraseSameRgn",
  283.  "oinvertSameRgn",
  284.  "ofillSameRgn",
  285.     "r8d","r8e","r8f",
  286.  "oBitsRect",
  287.  "oBitsRgn",
  288.     "r92","r93","r94","r95","r96","r97",
  289.  "oPackBitsRect",
  290.  "oPackBitsRgn",
  291.  "oOpcode9A",
  292.     "r9b","r9c","r9d","r9e","r9f",
  293.  "oShortComment",
  294.  "oLongComment",
  295.   0 };
  296.  
  297. //    /* a2..af",b0..fe unused */
  298. // "oopEndPic    = 0x00ff",
  299. //    /* 0100..ffff unused */
  300. // "oHeaderOp    = 0x0c00
  301. #endif
  302.     
  303.     
  304. typedef struct valName {
  305.     short    value;
  306.     char* name;
  307. } ValName;
  308.  
  309. static ValName QuickDrawFont[] = {
  310.     { 0,    "helvetica" },     /* Chicago */
  311.     { 1,    "helvetica" },  /* Geneva */
  312.     { 2,    "times" },            /* newYork */
  313.     { 3,    "helvetica" },    /* geneva */
  314.     { 4,    "courier" },        /* monaco */
  315.     { 5,    "times" },            /* venice */
  316.     { 6,    "times" },            /* london */
  317.     { 7,    "times" },            /* athens */
  318.     { 8,    "times" },            /* sanFran */
  319.     { 9,    "times" },            /* toronto */
  320.     { 11,    "times" },            /* cairo */
  321.     { 12,    "times" },            /* losAngeles */
  322.     { 13,    "times" },            /* Zapf Dingbats */
  323.     { 14,    "bookman" },        /* bookman */
  324.     { 16,    "palatino" },        /* palatino */
  325.     { 18,    "times" },            /* Zapf Chancery */
  326.     { 19,    "times" },            /* Sourvenir */
  327.     { 20,    "times" },            /* times */
  328.     { 21,    "helvetica" },
  329.     { 22,    "courier" },
  330.     { 23,    "symbol" },
  331.     { 24,    "times" },         /* taliesin */
  332.     { 26,    "times" },         /* Lubalin Graph */
  333.     { 33,    "avant garde" },         /* Avant Garde */
  334.     { 34,    "New Century Schlbk" },         /* New Century Schlbk */
  335.     { -1,    0 }
  336. };
  337.  
  338. #if 0
  339. Font[0] = 'Chicago'
  340. Font[1] = 'Geneva'
  341. Font[2] = 'New York'
  342. Font[3] = 'Geneva'
  343. Font[4] = 'Monaco'
  344. Font[13] = 'Zapf Dingbats'
  345. Font[14] = 'Bookman'
  346. Font[16] = 'Palatino'
  347. Font[18] = 'Zapf Chancery'
  348. Font[19] = 'Souvenir'
  349. Font[20] = 'Times'
  350. Font[21] = 'Helvetica'
  351. Font[22] = 'Courier'
  352. Font[23] = 'Symbol'
  353. Font[26] = 'Lubalin Graph'
  354. Font[33] = 'Avant Garde'
  355. Font[34] = 'New Century Schlbk'
  356. #endif
  357.     
  358.  
  359. Nlm_Boolean gPixColorsDone = false; // a hack !
  360.  
  361. #ifdef WIN_MOTIF
  362. static short gAllocatedColors[256];
  363. static short gNAllocatedColors = 0;
  364. #endif
  365.  
  366.  
  367. DDrawPict::DDrawPict() :
  368.     fVerbose(true), fPenshown(true), fUnclipped(true),
  369.     fPict(NULL), fAlign(0),
  370.     fFont(NULL), fFontname(NULL), fFontfamily(NULL),
  371.     fFontsize(12), fFontstyle(0), fLastFontnum(-1),
  372.     fNeedInstallFont(false),
  373.     fPictVersion(0), fPicsize(0)
  374. {
  375.     Nlm_LoadRect( &fPicRect, 0, 0, 0, 0);
  376.     Nlm_LoadRect( &fPicFrame, 0, 0, 0, 0);
  377.     Nlm_LoadRect( &fTheRect, 0, 0, 0, 0);
  378.     fOvSize.x= 0; 
  379.     fOvSize.y= 0;
  380.     fFontname= "Times";
  381.     fFontfamily= "Roman";
  382.     MakeXByteFlip();
  383.   gPixColorsDone= false;
  384. }
  385.  
  386. DDrawPict::~DDrawPict()
  387. {
  388.  
  389. }
  390.  
  391. //static
  392. void DDrawPict::Cleanup()
  393. {
  394. #ifdef WIN_MOTIF
  395.     if (gNAllocatedColors) {
  396.         short     i, j;
  397.       Display * display     = Nlm_currentXDisplay;
  398.       short     screenNum    = DefaultScreen( display);
  399.        Visual  * visual        = DefaultVisual( display, screenNum);
  400.        Colormap     colormap     = DefaultColormap( display, screenNum);  
  401.          
  402.         for (i=0; i<256; i++) {
  403.             short nalloc= gAllocatedColors[i];
  404.             unsigned long pixel= i;
  405.             for ( ; nalloc>0; nalloc--) 
  406.                 XFreeColors( display, colormap, &pixel, 1, 0L);
  407.             gAllocatedColors[i]= 0;
  408.             }
  409.         gNAllocatedColors= 0;
  410.         }
  411. #endif    
  412. }
  413.  
  414.  
  415.  
  416. byte    DDrawPict::getByte()
  417. {
  418.     byte b = *fPict++;
  419.     fAlign++;
  420. #ifdef PLIST
  421.     if (gDoPlist) fprintf( gPlist, " %2X", b); 
  422. #endif
  423.     return b;
  424. }
  425.  
  426. word DDrawPict::getWord()
  427. {
  428.     word b = *fPict++;
  429.     fAlign += 2;
  430.     b=  (b << 8) | *fPict++;
  431. #ifdef PLIST
  432.     if (gDoPlist) fprintf( gPlist, " %4X", b); 
  433. #endif
  434.     return b;
  435. }
  436.  
  437. longword DDrawPict::getLong()
  438. {
  439.     longword i = getWord();
  440.     i=  (i << 16) | getWord();
  441.     return i;
  442. }
  443.  
  444.  
  445. void DDrawPict::skipbytes( word count)
  446. {
  447. #ifdef PLIST
  448.     if (gDoPlist) {
  449.     fprintf( gPlist, " (skip %d)", count); 
  450.     for (short i=0; i< MIN(count,10); i++)
  451.         fprintf(gPlist, " %2X", fPict[i]);
  452.     }
  453. #endif
  454.     fAlign += count;
  455.     fPict += count;
  456. }
  457.  
  458. void DDrawPict::getbytes(char* buf, long bufsize)
  459. {
  460. #ifdef PLIST
  461.     if (gDoPlist) {
  462.     fprintf( gPlist, " (get %d)", bufsize); 
  463.     for (short i=0; i< MIN(bufsize,10); i++)
  464.         fprintf(gPlist, " %2X", fPict[i]);
  465.     }
  466. #endif
  467.     fAlign += bufsize;
  468.     MemCpy(buf, fPict, bufsize);
  469.     fPict += bufsize;
  470. }
  471.  
  472. word DDrawPict::getOpcode()
  473. {
  474.     word op;
  475.     
  476. #ifdef PLIST
  477.     if (gDoPlist) fprintf( gPlist, "\n"); 
  478. #endif
  479.     if (fPictVersion == 1)
  480.         op= getByte();
  481.     else {
  482.         if (fAlign & 1) {
  483. #ifdef PLIST
  484.             Boolean savep= gDoPlist; gDoPlist= false;
  485. #endif
  486.             (void) getByte();
  487. #ifdef PLIST
  488.             gDoPlist= savep;
  489. #endif
  490.             }
  491.         op= getWord();
  492.         }
  493.         
  494. #ifdef PLIST
  495.     if (!gDoPlist) ;
  496.     else if (op < 0xa2) fprintf( gPlist, "%#7x %-16s: ", fAlign, gOpnames[op]);
  497.     else fprintf( gPlist, "%#7x %#-16x: ",fAlign, op);
  498. #endif
  499.     return op;
  500. }
  501.  
  502.  
  503.  
  504.  
  505.  
  506. void DDrawPict::getRGBKolor( RGBkolor* acolor)
  507. {
  508.     acolor->red = getWord();
  509.     acolor->green= getWord();
  510.     acolor->blue= getWord();
  511. }
  512.  
  513. void DDrawPict::getPointAsis( Nlm_PointPtr apt)
  514. {
  515.     apt->y    = getWord();
  516.     apt->x    = getWord();
  517. }
  518.  
  519. void DDrawPict::getPointLocal( Nlm_PointPtr apt)
  520. {
  521.     long y    = ((signed short) getWord()) - fPicFrame.top  + fPicRect.top;
  522.     long x    = ((signed short) getWord()) - fPicFrame.left + fPicRect.left;
  523.     apt->y= MAX(-32565, MIN(32565, y)); //y;
  524.     apt->x= MAX(-32565, MIN(32565, x)); //x;
  525. }
  526.  
  527. void DDrawPict::getRectLocal( Nlm_RectPtr arect)
  528. {
  529.     long top        = ((signed short) getWord()); top  += fPicRect.top - fPicFrame.top;
  530.     long left        = ((signed short) getWord()); left += fPicRect.left - fPicFrame.left;
  531.     long bottom    = ((signed short) getWord()); bottom += fPicRect.top - fPicFrame.top;
  532.     long right    = ((signed short) getWord()); right += fPicRect.left - fPicFrame.left;
  533.     arect->top         = MAX(-32565, MIN(32565, top));
  534.     arect->left        = MAX(-32565, MIN(32565, left)); //(signed short)left;
  535.     arect->bottom    = MAX(-32565, MIN(32565, bottom)); //(signed short)bottom;
  536.     arect->right    = MAX(-32565, MIN(32565, right)); //(signed short)right;
  537. }
  538.  
  539. void DDrawPict::getRectAsis( Nlm_RectPtr arect)
  540. {
  541.     arect->top        = getWord();
  542.     arect->left        = getWord();
  543.     arect->bottom    = getWord();
  544.     arect->right    = getWord();
  545. }
  546.  
  547.  
  548. void DDrawPict::skipPolyOrRegion(void)
  549. {
  550.     skipbytes( getWord() - 2);
  551. }
  552.  
  553.  
  554. #ifdef WIN_MOTIF
  555. #define COPY_MODE   1
  556. #define MERGE_MODE  2
  557. #define INVERT_MODE 3
  558. #define ERASE_MODE  4
  559.  
  560. static byte    XByteFlip [256];
  561.  
  562. void DDrawPict::MakeXByteFlip()
  563. {
  564.     short i, j;
  565.   byte val, inv;
  566.  
  567.   for (i = 0; i < 256; i++) {
  568.     inv = 0;
  569.     val = (byte) i;
  570.     for (j = 0; j < 8; j++) {
  571.       inv = (inv << 1);
  572.       inv += (val % 2);
  573.       val = (val >> 1);
  574.     }
  575.     XByteFlip[i] = inv;
  576.   }
  577. }
  578.  
  579. #else
  580.  
  581. void DDrawPict::MakeXByteFlip()
  582. {
  583. }
  584. #endif
  585.  
  586.  
  587. byte* DDrawPict::expandbuf(byte* buf, short* len, short bitsPerPixel)
  588. {
  589.     static byte pixbuf[256 * 8];
  590.     register byte* src;
  591.     register byte* dst;
  592.     register int i;
  593.  
  594.     src = buf;
  595.     dst = pixbuf;
  596.  
  597.     switch (bitsPerPixel) {
  598.     case 8:
  599.     case 16:
  600.     case 32:
  601.         return buf;
  602.     case 4:
  603.         for (i = 0; i < *len; i++) {
  604.             *dst++ = (*src >> 4) & 15;
  605.             *dst++ = *src++ & 15;
  606.         }
  607.         *len *= 2;
  608.         break;
  609.     case 2:
  610.         for (i = 0; i < *len; i++) {
  611.             *dst++ = (*src >> 6) & 3;
  612.             *dst++ = (*src >> 4) & 3;
  613.             *dst++ = (*src >> 2) & 3;
  614.             *dst++ = *src++ & 3;
  615.         }
  616.         *len *= 4;
  617.         break;
  618.     case 1:
  619.         for (i = 0; i < *len; i++) {
  620.             *dst++ = (*src >> 7) & 1;
  621.             *dst++ = (*src >> 6) & 1;
  622.             *dst++ = (*src >> 5) & 1;
  623.             *dst++ = (*src >> 4) & 1;
  624.             *dst++ = (*src >> 3) & 1;
  625.             *dst++ = (*src >> 2) & 1;
  626.             *dst++ = (*src >> 1) & 1;
  627.             *dst++ = *src++ & 1;
  628.         }
  629.         *len *= 8;
  630.         break;
  631.     default:
  632.         if (fVerbose) { Nlm_Message(MSG_OK,"drawpict:bad bits per pixel in expandbuf"); fVerbose= false; }
  633.     }
  634.     return pixbuf;
  635. }
  636.  
  637.  
  638. #define DONTEXPAND 1
  639.  
  640.  
  641. void DDrawPict::unpackSmallLine( long irow, unsigned char* linebuf, unsigned char* bits, unsigned char* bitsend, 
  642.                                                                     unsigned short rowBytes, short pixelSize)
  643. {
  644.     short buflen = rowBytes;
  645.     byte     abyte, *pbits, *bytepixels;
  646.     Nlm_Boolean isBitmap = pixelSize < 2;
  647.     long    j;
  648.     
  649.     getbytes((char*) linebuf, buflen);
  650. #if DONTEXPAND
  651. #ifdef WIN_MSWIN
  652.     if (!isBitmap) pbits= bitsend - irow*rowBytes;
  653.     else
  654. #endif
  655.     pbits = bits + irow*rowBytes; 
  656.     bytepixels= linebuf;
  657. #else
  658.     pbits = bits + irow * pixwidth;
  659.     bytepixels = expandbuf( linebuf, &buflen, pixelSize);
  660. #endif
  661.  
  662.     for (j = 0; j < buflen; j++) {
  663.         abyte= *bytepixels++;
  664. #ifdef WIN_MSWIN
  665.         if (isBitmap) abyte= (byte) ~abyte;
  666. #endif
  667. #ifdef WIN_MOTIF
  668.         if (isBitmap) abyte= XByteFlip[abyte];
  669. #endif
  670.         *pbits++ = abyte;
  671.         }
  672. }
  673.  
  674.  
  675. void DDrawPict::unpackBigLine( long irow, unsigned char* linebuf, unsigned char* bits, unsigned char* bitsend, 
  676.                                                                 unsigned short rowBytes, short pixelSize, short pkpixsize)
  677. {
  678.     enum { kFudgebuf = 300 };
  679.     word   buflen = rowBytes;
  680.     byte      abyte, *pbits, *bytepixels;
  681.     Nlm_Boolean isBitmap = pixelSize < 2;
  682.     long     j, k, l;
  683.     short  linelen, len;
  684.     
  685. #ifdef WIN_MSWIN
  686.     if (!isBitmap) pbits= bitsend - irow*rowBytes;
  687.     else
  688. #endif
  689.     pbits = bits + irow * rowBytes; // pixwidth; 
  690.  
  691.     if (rowBytes > 250 || pixelSize > 8)
  692.         linelen = getWord();
  693.     else
  694.         linelen = getByte();
  695.  
  696.     if (linelen >= kFudgebuf+rowBytes)   
  697.         Nlm_Message(MSG_FATAL,"DDrawPict::linelen > rowbytes");
  698.  
  699.     getbytes((char*) linebuf, linelen);
  700.     
  701.     for (j = 0; j < linelen; ) {
  702.         if (linebuf[j] & 0x80) {
  703.             len = ((linebuf[j] ^ 255) & 255) + 2;
  704.             buflen = pkpixsize;
  705. #if DONTEXPAND
  706.             bytepixels= linebuf + j+1;
  707. #else
  708.             bytepixels = expandbuf(linebuf + j+1, &buflen, pixelSize);
  709. #endif
  710.  
  711.             for (k = 0; k < len; k++) {
  712.                 for (l = 0; l < buflen; l++) {
  713.                     abyte= *bytepixels++;
  714. #ifdef WIN_MSWIN
  715.                     if (isBitmap) abyte= (byte) ~abyte;
  716. #endif
  717. #ifdef WIN_MOTIF
  718.                     if (isBitmap) abyte= XByteFlip[abyte];
  719. #endif
  720.                     *pbits++ = abyte;
  721.                     }
  722.                 bytepixels -= buflen;
  723.                 }
  724.             j += 1 + pkpixsize;
  725.             }
  726.         else {
  727.             len = (linebuf[j] & 255) + 1;
  728.             buflen = len * pkpixsize;
  729. #if DONTEXPAND
  730.             bytepixels= linebuf + j+1;
  731. #else
  732.             bytepixels = expandbuf(linebuf + j+1, &buflen, pixelSize);
  733. #endif
  734.             for (k = 0; k < buflen; k++) {
  735.                     abyte= *bytepixels++;
  736. #ifdef WIN_MSWIN
  737.                     if (isBitmap) abyte= (byte) ~abyte;
  738. #endif
  739. #ifdef WIN_MOTIF
  740.                     if (isBitmap) abyte= XByteFlip[abyte];
  741. #endif
  742.                     *pbits++ = abyte;
  743.                     }
  744.             j += len * pkpixsize + 1;
  745.             }
  746.         }
  747. }
  748.  
  749.  
  750.  
  751. byte* DDrawPict::unpackbits( Nlm_RectPtr bounds, word rowBytes, short pixelSize, 
  752.                                                         ulong& unpackSize)
  753. {
  754.     enum { kFudgebuf = 300 };
  755.     byte *linebuf;
  756.     byte abyte, *bits, *pbits, *bitsend;
  757.     register long irow,j,k,l;
  758.     word  pixwidth;
  759.     short linelen, len;
  760.     byte* bytepixels;
  761.     short buflen, pkpixsize, rowsize;
  762.     Nlm_Boolean isBitmap = (pixelSize < 2);
  763.     
  764.   unpackSize= 0;
  765.     if (pixelSize <= 8) rowBytes &= 0x7fff;
  766.     pixwidth = bounds->right - bounds->left;
  767.  
  768.     pkpixsize = 1;
  769.     if (pixelSize == 16) {
  770.         pkpixsize = 2;
  771.         pixwidth *= 2;
  772.         }
  773.     else if (pixelSize == 32)
  774.         pixwidth *= 3;
  775.     
  776.     if (rowBytes == 0) rowBytes = pixwidth;
  777.  
  778. #if DONTEXPAND
  779.     /* dgg -- don't need 1byte/pixel, not expanding... */
  780.     rowsize = rowBytes;
  781. #else
  782.     rowsize = pixwidth;
  783.     if (rowBytes < 8) rowsize = 8 * rowBytes;    /* worst case expansion factor */
  784. #endif
  785.  
  786.     unpackSize= rowsize * (bounds->bottom - bounds->top);
  787.     bits = (byte*)Nlm_MemNew( (unpackSize + 8) * sizeof(byte) );
  788.     if (!bits) Nlm_Message(MSG_FATAL, "drawpict:no mem for packbits rectangle");
  789.         
  790.     linebuf = (byte*)Nlm_MemNew(rowBytes + kFudgebuf);
  791.     if (!linebuf) Nlm_Message(MSG_FATAL,"drawpict:can't allocate memory for line buffer");
  792.  
  793.     bitsend= bits + rowBytes * (bounds->bottom - bounds->top - 1);
  794.     if (rowBytes < 8) {
  795.         for (irow = 0; irow < bounds->bottom - bounds->top; irow++)
  796.             //unpackSmallLine(irow, linebuf, bits, bitsend, rowBytes, pixelSize);
  797. ///***********
  798.         {
  799.             buflen = rowBytes;
  800.             getbytes((char*) linebuf, buflen);
  801. #if DONTEXPAND
  802. #ifdef WIN_MSWIN
  803.             if (!isBitmap) pbits= bitsend - irow*rowBytes;
  804.             else
  805. #endif
  806.             pbits = bits + irow * rowBytes; // pixwidth; 
  807.             bytepixels= linebuf;
  808. #else
  809.             pbits = bits + irow * pixwidth;
  810.             bytepixels = expandbuf(linebuf, &buflen, pixelSize);
  811. #endif
  812.  
  813.             for (j = 0; j < buflen; j++) {
  814.                 abyte= *bytepixels++;
  815. #ifdef WIN_MSWIN
  816.                 if (isBitmap) abyte= (byte) ~abyte;
  817. #endif
  818. #ifdef WIN_MOTIF
  819.                 if (isBitmap) abyte= XByteFlip[abyte];
  820. #endif
  821.                  *pbits++ = abyte;
  822.                 }
  823.             }
  824. //****************/
  825.  
  826.         }
  827.         
  828.     else {
  829.         for (irow = 0; irow < bounds->bottom - bounds->top; irow++) 
  830.             //unpackBigLine(irow, linebuf, bits, bitsend, rowBytes, pixelSize, pkpixsize);
  831.  
  832.         {
  833. #if 1
  834. #ifdef WIN_MSWIN
  835.             if (!isBitmap) pbits= bitsend - irow*rowBytes;
  836.             else
  837. #endif
  838.             pbits = bits + irow * rowBytes;  
  839. #else
  840.             pbits = bits + irow * pixwidth;
  841. #endif
  842.  
  843.             if (rowBytes > 250 || pixelSize > 8)
  844.                 linelen = getWord();
  845.             else
  846.                 linelen = getByte();
  847.  
  848.             if (linelen >= kFudgebuf+rowBytes)   
  849.                 Nlm_Message(MSG_FATAL,"drawpict:linelen > rowbytes");
  850.      
  851.             getbytes((char*) linebuf, linelen);
  852.             
  853.             for (j = 0; j < linelen; ) {
  854.                 if (linebuf[j] & 0x80) {
  855.                     len = ((linebuf[j] ^ 255) & 255) + 2;
  856.                     buflen = pkpixsize;
  857. #if DONTEXPAND
  858.                     bytepixels= linebuf + j+1;
  859. #else
  860.                     bytepixels = expandbuf(linebuf + j+1, &buflen, pixelSize);
  861. #endif
  862.                     for (k = 0; k < len; k++) {
  863.                         for (l = 0; l < buflen; l++) {
  864.                             abyte= *bytepixels++;
  865. #ifdef WIN_MSWIN
  866.                             if (isBitmap) abyte= (byte) ~abyte;
  867. #endif
  868. #ifdef WIN_MOTIF
  869.                             if (isBitmap) abyte= XByteFlip[abyte];
  870. #endif
  871.                             *pbits++ = abyte;
  872.                             }
  873.                         bytepixels -= buflen;
  874.                         }
  875.                     j += 1 + pkpixsize;
  876.                     }
  877.                 else {
  878.                     len = (linebuf[j] & 255) + 1;
  879.                     buflen = len * pkpixsize;
  880. #if DONTEXPAND
  881.                     bytepixels= linebuf + j+1;
  882. #else
  883.                     bytepixels = expandbuf(linebuf + j+1, &buflen, pixelSize);
  884. #endif
  885.                     for (k = 0; k < buflen; k++) {
  886.                             abyte= *bytepixels++;
  887. #ifdef WIN_MSWIN
  888.                             if (isBitmap) abyte= (byte) ~abyte;
  889. #endif
  890. #ifdef WIN_MOTIF
  891.                             if (isBitmap) abyte= XByteFlip[abyte];
  892. #endif
  893.                             *pbits++ = abyte;
  894.                             }
  895.                     j += len * pkpixsize + 1;
  896.                     }
  897.                 }
  898.             }
  899. ///************************/
  900.  
  901.         }
  902.  
  903.     Nlm_MemFree(linebuf);
  904.     return bits;
  905. }
  906.  
  907.  
  908.  
  909.  
  910. void DDrawPict::read_pixmap(PIXMapPtr p, word* rowBytes)
  911. {
  912.     Nlm_RecT    arec;
  913.     if (rowBytes != NULL) *rowBytes = getWord();
  914.  
  915.     getRectAsis( &arec);
  916.     p->Bounds.left= arec.left;
  917.     p->Bounds.top= arec.top;
  918.     p->Bounds.right= arec.right;
  919.     p->Bounds.bottom= arec.bottom;
  920.     p->pmVersion = getWord();
  921.     p->packType = getWord();
  922.     p->packSize = getLong();
  923.     p->hRes = getLong();
  924.     p->vRes = getLong();
  925.     p->pixelType = getWord();
  926.     p->pixelSize = getWord();
  927.     p->cmpCount = getWord();
  928.     p->cmpSize = getWord();
  929.     p->planeBytes = getLong();
  930.     p->pmTable = getLong();
  931.     p->pmReserved = getLong();
  932.  
  933.     if (p->pixelType != 0)
  934.         Nlm_Message(MSG_FATAL,"drawpict: sorry, I only do chunky format");
  935.     if (p->cmpCount != 1)
  936.         Nlm_Message(MSG_FATAL,"drawpict: sorry, cmpCount != 1");
  937.     if (p->pixelSize != p->cmpSize)
  938.         Nlm_Message(MSG_FATAL,"drawpict: oops, pixelSize != cmpSize");
  939. }
  940.  
  941.  
  942. KolorTable DDrawPict::read_colour_table(void)
  943. {
  944.     longword ctSeed;
  945.     word ctFlags;
  946.     word ctSize;
  947.     word val;
  948.     long i;
  949.     /* RGBKolorPtr colour_table;*/
  950.     KolorTable    kolorTab;
  951.     KolorSpec*    kolors;
  952.     
  953.     kolorTab.ctSeed = ctSeed = getLong();
  954.     kolorTab.ctFlags = ctFlags =  getWord();
  955.     kolorTab.ctSize = ctSize = getWord();
  956.  
  957. #if 0
  958.     kolorTab.ctSeed = ctSeed= 1023; /* == minSeed in qd colormanager */
  959. #endif
  960.  
  961.     kolors = (KolorSpec*) Nlm_MemNew( sizeof(KolorSpec) * (ctSize + 1));
  962.     if (kolors == NULL)
  963.         Nlm_Message(MSG_FATAL,"drawpict: no memory for colors table");
  964.     kolorTab.ctTable= kolors;
  965.     
  966.     for (i = 0; i <= ctSize; i++) {
  967.         val = getWord();
  968.         if (ctFlags & 0x8000) val = i;
  969.         if (val > ctSize)
  970.             Nlm_Message(MSG_FATAL,"drawpict: pixel value greater than colour table size");
  971.         kolors[val].value= val;
  972.         kolors[val].rgb.red = getWord();
  973.         kolors[val].rgb.green = getWord();
  974.         kolors[val].rgb.blue = getWord();
  975.         }
  976.  
  977.     return kolorTab;
  978. }
  979.  
  980.  
  981. void DDrawPict::read_pattern(void)
  982. {
  983.     word         PatType;
  984.     word         rowBytes;
  985.     PIXMap     p;
  986.     byte*         bits;
  987.     KolorTable     ct;
  988.     Nlm_RecT    arec;
  989.     ulong    unpackSize;
  990.     
  991.     PatType = getWord();
  992.     switch (PatType) {
  993.     case 2:
  994.         skipbytes(8); /* old pattern data */
  995.         skipbytes(5); /* RGB for pattern */
  996.         break;
  997.     case 1:
  998.         skipbytes(8); /* old pattern data */
  999.         read_pixmap(&p, &rowBytes);
  1000.         ct = read_colour_table();
  1001.         arec.left= p.Bounds.left;
  1002.         arec.top= p.Bounds.top;
  1003.         arec.right= p.Bounds.right;
  1004.         arec.bottom= p.Bounds.bottom;
  1005.         bits = unpackbits(&arec, rowBytes, p.pixelSize, unpackSize);
  1006.         Nlm_MemFree(bits);
  1007.         Nlm_MemFree(ct.ctTable);
  1008.         break;
  1009.     default:
  1010.         Nlm_Message(MSG_FATAL,"drawpict: unknown pattern type in read_pattern");
  1011.     }
  1012. }
  1013.  
  1014.  
  1015.  
  1016.  
  1017. #ifdef WIN_MOTIF
  1018. // static
  1019. Local void FindXColor( Display *dsp, Colormap cmap, XColor* colr)
  1020. {
  1021.      long  i, match, cindx, numCells;
  1022.   long  rd, gd, bd, dist, mindist;
  1023.   static XColor defColrs[256];
  1024.   static Boolean haveColrs= false;
  1025.  
  1026.               // must leave some of 256 colors for other apps
  1027.               // damn X for its messy color handling !
  1028.   if (gNAllocatedColors < 248) 
  1029.       match= XAllocColor( dsp, cmap, colr);
  1030.   else
  1031.       match= 0;
  1032.       
  1033.   if (match == 0) {
  1034.     numCells= DisplayCells( dsp, DefaultScreen(dsp));
  1035.     if (!haveColrs) {
  1036.       for (i=0; i<numCells; i++) defColrs[i].pixel= i;
  1037.       XQueryColors( dsp, cmap, defColrs, numCells);
  1038.       haveColrs= true;
  1039.       }
  1040.     mindist= 196608; // 256 * 256 * 3  
  1041.     //mindist= 768; // 256 * 3 */
  1042.     cindx= colr->pixel;
  1043.     for (i= 0; i<numCells; i++) {
  1044.       rd= (defColrs[i].red >> 8) - (colr->red >> 8);
  1045.       gd= (defColrs[i].green >> 8) - (colr->green >> 8);
  1046.       bd= (defColrs[i].blue >> 8) - (colr->blue >> 8);
  1047.       dist= (rd * rd) + (gd * gd) + (bd * bd);
  1048.       //dist= abs(rd) + abs(gd) + abs(bd);
  1049.       if (dist < mindist) {
  1050.          mindist= dist;
  1051.          cindx= defColrs[i].pixel;
  1052.          if (dist==0) break;
  1053.          }
  1054.       }
  1055.     colr->pixel= cindx;
  1056.     colr->red  = defColrs[cindx].red;
  1057.     colr->green= defColrs[cindx].green;
  1058.     colr->blue = defColrs[cindx].blue;
  1059.     }
  1060.   else {
  1061.     if (gNAllocatedColors==0) {
  1062.         for (i=0; i<256; i++) gAllocatedColors[i]= 0;
  1063.         }
  1064.     gAllocatedColors[colr->pixel]++;
  1065.     if (gAllocatedColors[colr->pixel] == 1) {
  1066.         gNAllocatedColors++;
  1067.         haveColrs= 0;
  1068.         }
  1069.     }
  1070. }
  1071. #endif
  1072.  
  1073.  
  1074. // static
  1075. void DDrawPict::Pixmap2Xcolors( KolorTable& kolorTab, unsigned char* bits, ulong bitsize,
  1076.                                                                     Nlm_Boolean returnXtabInBits)
  1077. {
  1078. #ifdef WIN_MOTIF
  1079.     if (!(kolorTab.ctFlags & kXColorTableFlag)) {
  1080.         byte         xtab[256], ival, abyte;
  1081.       short     ic;
  1082.       XColor    xcol;
  1083.       Display * display = Nlm_currentXDisplay;
  1084.       short   screenNum= DefaultScreen( display);
  1085.         Visual     * visual= DefaultVisual( display, screenNum);
  1086.         Colormap colormap = DefaultColormap( display, screenNum);    
  1087.     
  1088.         xcol.flags= DoRed | DoGreen | DoBlue;
  1089.         for (ic=0; ic <= kolorTab.ctSize; ic++) {
  1090.             ival= (byte) kolorTab.ctTable[ic].value;
  1091.             xcol.red=   kolorTab.ctTable[ic].rgb.red;
  1092.             xcol.green= kolorTab.ctTable[ic].rgb.green;
  1093.             xcol.blue=  kolorTab.ctTable[ic].rgb.blue;
  1094.             FindXColor( display, colormap, &xcol);
  1095.             xtab[ival]= (byte) xcol.pixel;
  1096.             }
  1097.         kolorTab.ctFlags |= kXColorTableFlag;
  1098.         
  1099.         if (returnXtabInBits && bits && bitsize >= 256) {
  1100.             for (ic= 0; ic < 256; ic++) bits[ic]= xtab[ic];
  1101.             }
  1102.         else if (bits) {
  1103.             register byte* pbits= bits;
  1104.             for (long ib= 0; ib<bitsize; ib++) { 
  1105.                 //abyte= XByteFlip[*pbits]; //must use unflipped vals, fix now in unpackbits
  1106.                 *pbits= (byte) xtab[*pbits];
  1107.                 pbits++;
  1108.                 }
  1109.             }
  1110.         }
  1111. #endif
  1112. }
  1113.  
  1114.  
  1115.  
  1116.  
  1117. void DDrawPict::drawPixmap( short version, word rowBytes, short isregion )
  1118. {
  1119.     word         mode;
  1120.     PIXMap     p;
  1121.     word         pixwidth;
  1122.     byte        * bits;
  1123.     KolorTable    kolorTab;
  1124.     Nlm_RecT    arec, sourcerec, destrec;
  1125.     ulong        unpackSize;
  1126.     
  1127.     read_pixmap(&p, NULL);
  1128.     pixwidth = p.Bounds.right - p.Bounds.left;
  1129.     kolorTab = read_colour_table();
  1130.  
  1131.     getRectAsis(&sourcerec);
  1132.     getRectLocal( &destrec);
  1133.     mode = getWord();
  1134.     if (isregion) skipPolyOrRegion();
  1135.  
  1136.     arec.left= p.Bounds.left;
  1137.     arec.top= p.Bounds.top;
  1138.     arec.right= p.Bounds.right;
  1139.     arec.bottom= p.Bounds.bottom;
  1140.     bits = unpackbits( &arec, rowBytes, p.pixelSize, unpackSize);
  1141.     if (!bits) return;
  1142.  
  1143. #ifdef WIN_MAC
  1144.     {
  1145.     Nlm_RectTool   srcRect, dstRect;
  1146.     PixMap        srcBits;
  1147.     GrafPtr       port;
  1148.     CTabHandle    cthand;
  1149.     long                ic, ctsize;
  1150.     //PaletteHandle oldph,ph;
  1151.     
  1152.     cthand= NULL;
  1153.     ctsize = (kolorTab.ctSize + 1) * sizeof(ColorSpec);
  1154.     cthand= (CTabHandle) NewHandle(sizeof(ColorTable) + ctsize);
  1155.     if (cthand) {
  1156.         (**cthand).ctSeed = kolorTab.ctSeed;
  1157.         (**cthand).ctFlags= kolorTab.ctFlags;
  1158.         (**cthand).ctSize = kolorTab.ctSize;
  1159.         /* MemCpy( &(**cthand).ctTable, &(kolorTab.ctTable), ctsize); */
  1160.         for (ic=0; ic <= kolorTab.ctSize; ic++) {
  1161.             (**cthand).ctTable[ic].value= kolorTab.ctTable[ic].value;
  1162.             (**cthand).ctTable[ic].rgb.red= kolorTab.ctTable[ic].rgb.red;
  1163.             (**cthand).ctTable[ic].rgb.green= kolorTab.ctTable[ic].rgb.green;
  1164.             (**cthand).ctTable[ic].rgb.blue= kolorTab.ctTable[ic].rgb.blue;
  1165.             }
  1166.         }
  1167.         
  1168.     Nlm_RecTToRectTool( &sourcerec, &srcRect);
  1169.     Nlm_RecTToRectTool( &destrec, &dstRect);
  1170.  
  1171.     srcBits.pmVersion= p.pmVersion;
  1172.     srcBits.packType= p.packType;
  1173.     srcBits.packSize= p.packSize;
  1174.     srcBits.hRes= p.hRes;
  1175.     srcBits.vRes= p.vRes;
  1176.     srcBits.pixelType= p.pixelType;
  1177.     srcBits.pixelSize= p.pixelSize;
  1178.     srcBits.cmpCount= p.cmpCount;
  1179.     srcBits.cmpSize= p.cmpSize;
  1180.     srcBits.planeBytes= p.planeBytes;
  1181.     srcBits.pmTable= cthand; 
  1182.     srcBits.pmReserved= p.pmReserved;
  1183.     
  1184.     srcBits.bounds.left= p.Bounds.left;
  1185.     srcBits.bounds.top = p.Bounds.top;
  1186.     srcBits.bounds.right= p.Bounds.right;
  1187.     srcBits.bounds.bottom= p.Bounds.bottom;
  1188.     srcBits.baseAddr = (Ptr) bits;
  1189.     srcBits.rowBytes = rowBytes;  
  1190.     
  1191.     GetPort (&port);
  1192.  
  1193.     CopyBits( (BitMap*) &srcBits, &port->portBits, &srcRect, &dstRect, mode, NULL);
  1194.     if (cthand) DisposHandle((Handle)cthand);
  1195.     Nlm_MemFree( bits);
  1196.  
  1197.     }
  1198. #endif
  1199.  
  1200.  
  1201. #ifdef WIN_MSWIN
  1202.   {
  1203.     HBITMAP       hBitmap, hOldBitmap;
  1204.     HDC           hMemoryDC, hDC;
  1205.     Nlm_Int4      dbisize, wmode;
  1206.     Nlm_Int2      ic, dwidth, dheight, swidth, sheight, rows, depth;
  1207.     BITMAPINFO        *dbi;
  1208.  
  1209.       depth= p.pixelSize; /* ?! check display depth */
  1210.         switch (mode) {
  1211.             /* translate apple to x modes */
  1212.             case 0: case 8: wmode = SRCCOPY; break;  /* srcCopy */
  1213.             case 1: case 9: wmode = SRCAND; break; /* srcOr */
  1214.             case 2: case 10: wmode = 0x00990066; break;   /* srcXor */
  1215.             case 3: case 11: wmode = MERGEPAINT; break;   /* srcBic */
  1216.             default:     wmode = SRCCOPY; /*WHITENESS;*/ break;
  1217.             }
  1218.  
  1219.     hDC= GetDC( Nlm_currentHWnd); //Nlm_currentHDC; /*GetDC( Nlm_currentHWnd); */
  1220.     if (bits && hDC) {
  1221.             dwidth= destrec.right - destrec.left;
  1222.             dheight= destrec.bottom - destrec.top;
  1223.             swidth= p.Bounds.right - p.Bounds.left;
  1224.             sheight= p.Bounds.bottom - p.Bounds.top;
  1225.  
  1226. #if 1
  1227.             dbisize= sizeof(BITMAPINFOHEADER) + (kolorTab.ctSize+1) * sizeof(RGBQUAD);
  1228.             dbi= (BITMAPINFO*) MemGet( dbisize, TRUE);
  1229.             dbi->bmiHeader.biSize= sizeof(BITMAPINFOHEADER); /* dbisize; */
  1230.             dbi->bmiHeader.biWidth= swidth;
  1231.             dbi->bmiHeader.biHeight= sheight;
  1232.             dbi->bmiHeader.biPlanes= 1; /*p.planeBytes; */
  1233.             dbi->bmiHeader.biBitCount=  p.pixelSize;
  1234.             dbi->bmiHeader.biCompression= 0;
  1235.             dbi->bmiHeader.biSizeImage= 0;
  1236.             dbi->bmiHeader.biClrUsed= kolorTab.ctSize + 1; 
  1237.             for (ic=0; ic <= kolorTab.ctSize; ic++) {
  1238.                 /* !??! need to remap kolorTab if (table[ic].value != ic) !!! */
  1239.                 dbi->bmiColors[ic].rgbRed= (byte) (kolorTab.ctTable[ic].rgb.red >>8);
  1240.                 dbi->bmiColors[ic].rgbGreen= (byte) (kolorTab.ctTable[ic].rgb.green >>8);
  1241.                 dbi->bmiColors[ic].rgbBlue= (byte) (kolorTab.ctTable[ic].rgb.blue >>8);
  1242.                 }
  1243.  
  1244. #if 1
  1245.             hMemoryDC = CreateCompatibleDC (hDC);
  1246. #if 0
  1247.             // ?? is the 1st param == hDC or hMemoryDC
  1248.             hBitmap= CreateDIBitmap( hDC, &(dbi->bmiHeader), 0, NULL, NULL, 0);
  1249.             if (hBitmap) {
  1250.                  SetDIBits( hDC, hBitmap, 0, sheight, bits, dbi, DIB_RGB_COLORS);
  1251.                 }
  1252. #else
  1253.             hBitmap= CreateDIBitmap( hDC, &(dbi->bmiHeader), CBM_INIT, bits, dbi, DIB_RGB_COLORS);
  1254. #endif
  1255.  
  1256.             hOldBitmap = (HBITMAP) SelectObject (hMemoryDC, hBitmap);
  1257.             if (hOldBitmap != NULL) {
  1258.                 /*SetViewportOrg( hDC, 0, destrec.bottom);*/
  1259.                 BitBlt ( hDC, destrec.left, destrec.top, swidth, sheight,
  1260.                                 hMemoryDC, 0, 0, wmode);
  1261.               /*SetViewportOrg( hDC, 0, 0); */ 
  1262.                 SelectObject (hMemoryDC, hOldBitmap);
  1263.                 }
  1264.             DeleteDC (hMemoryDC);
  1265.             DeleteObject (hBitmap);
  1266.             /* ReleaseDC( Nlm_currentHWnd, hDC); */
  1267. #else
  1268.             /* hDC= CreateCompatibleDC(Nlm_currentHDC);*/ /*?? or BeginPaint()... */
  1269.  
  1270.             /* SetViewportOrg( hDC, 0, -destrec.bottom); */
  1271.             SetDIBitsToDevice( hDC, destrec.left, destrec.top, swidth, sheight,
  1272.                     0, 0, swidth, sheight, (LPSTR) bits, (LPBITMAPINFO) dbi, DIB_RGB_COLORS
  1273.                     ); /* , wmode); */
  1274.             /* SetDIBitsToDevice StretchDIBits */
  1275.             /* SetViewportOrg( hDC, 0, 0);   */
  1276.  
  1277.             ReleaseDC( Nlm_currentHWnd, hDC);
  1278.             /*DeleteDC (hMemoryDC); */
  1279. #endif
  1280.  
  1281.             MemFree(dbi);
  1282. #else
  1283.             hBitmap = CreateBitmap ( swidth, sheight, 1, depth, (LPSTR) bits);
  1284.             hMemoryDC = CreateCompatibleDC (Nlm_currentHDC);
  1285.       hOldBitmap = SelectObject (hMemoryDC, hBitmap);
  1286.       if (hOldBitmap != NULL) {
  1287.                 BitBlt (Nlm_currentHDC, destrec.left, destrec.top, swidth, sheight,
  1288.                                 hMemoryDC, 0, 0, wmode);
  1289.                 SelectObject (hMemoryDC, hOldBitmap);
  1290.                 }
  1291.             DeleteDC (hMemoryDC);
  1292.             DeleteObject (hBitmap);
  1293. #endif
  1294.             }
  1295.     }
  1296.     Nlm_MemFree( bits);
  1297. #endif
  1298.  
  1299.  
  1300. #ifdef WIN_MOTIF
  1301.     {
  1302.     short   depth, width, height, xmode;
  1303.     XImage    *ximage;
  1304.     Pixmap  pixmap;
  1305.     GC             drawGC;
  1306.   short        ic, flag;
  1307.   XColor    xcol;
  1308.   byte  * pbits = bits;
  1309.   Display *display = Nlm_currentXDisplay;
  1310.   short   screenNum= DefaultScreen(display);
  1311.     Visual * visual= DefaultVisual( display, screenNum);
  1312.     Colormap colormap = DefaultColormap( display, screenNum);    
  1313.  
  1314.   width  = destrec.right - destrec.left;
  1315.   height = destrec.bottom - destrec.top;
  1316.   depth  = p.pixelSize; /* ?! check display depth */
  1317.   switch (mode) {
  1318.         /* translate apple to x modes */
  1319.       default: xmode= COPY_MODE;
  1320.       }
  1321.  
  1322.  
  1323.     Pixmap2Xcolors( kolorTab, bits, unpackSize, false);
  1324. #if 0
  1325.     {
  1326.     byte xtab[256], ival, abyte;
  1327.     xcol.flags= DoRed | DoGreen | DoBlue;
  1328.     for (ic=0; ic <= kolorTab.ctSize; ic++) {
  1329.         ival= (byte) kolorTab.ctTable[ic].value;
  1330.         xcol.red=   kolorTab.ctTable[ic].rgb.red;
  1331.         xcol.green= kolorTab.ctTable[ic].rgb.green;
  1332.         xcol.blue=  kolorTab.ctTable[ic].rgb.blue;
  1333.         FindXColor( display, colormap, &xcol);
  1334.         xtab[ival]= (byte) xcol.pixel;
  1335.         }
  1336.         
  1337.     long isize= unpackSize; //width * height;
  1338.     pbits= bits;
  1339.     for (long ib= 0; ib<isize; ib++) { 
  1340.         //abyte= XByteFlip[*pbits]; // !! YES !! ?? do we need to unflip this for pixmap !? (not for bitmap)
  1341.         *pbits= (byte) xtab[*pbits];
  1342.         pbits++;
  1343.         }
  1344.     pbits= bits;
  1345.     }
  1346. #endif
  1347.  
  1348. #if 0
  1349.     if (!gPixColorsDone &&  p.pixelSize <= 8)  {
  1350.      // this jazz is a hack good only for 8bit pixels (or less??) !!
  1351.    byte xtab[256], ival;
  1352.    gPixColorsDone= true;
  1353.  
  1354. /* need to do something about color table -- in GC ?? */
  1355.     xcol.flags= DoRed | DoGreen | DoBlue;
  1356.         for (ic=0; ic <= kolorTab.ctSize; ic++) {
  1357.         ival= kolorTab.ctTable[ic].value;
  1358.                 xcol.red=   kolorTab.ctTable[ic].rgb.red;
  1359.                 xcol.green= kolorTab.ctTable[ic].rgb.green;
  1360.                 xcol.blue=  kolorTab.ctTable[ic].rgb.blue;
  1361. // damn xwin won't let me use colortab mapping !? stupid get
  1362.                  //XStoreColor( display, colormap, &xcol);
  1363.         XAllocColor( display, colormap, &xcol);
  1364.         xtab[ival]= xcol.pixel;
  1365.        }
  1366.  
  1367. // damn so we do it the hard way and change all pixmap bits values !
  1368. // Double Damn -- can't do this on each redraw !! only once !!!
  1369.    byte cval;
  1370.    for (long ib= 0; ib<unpackSize; ib++) {
  1371.            cval= (byte) bits[ib];
  1372.       bits[ib]= xtab[cval];
  1373.       }
  1374. }
  1375. #endif
  1376.  
  1377.         short rowpad = 8; // 8,16 or 32 bits.  Use 16 if rowbytes == 1 + width !? for short pad
  1378.     short bitsoffset= 0;
  1379.     ximage = XCreateImage ( display, visual,
  1380.                                 depth, ZPixmap, bitsoffset, (char *) pbits, 
  1381.                         width, height, rowpad, rowBytes & 0x7fff);
  1382.         if (ximage) {
  1383.             pixmap = XCreatePixmap(display, Nlm_currentXWindow, width, height, depth);
  1384.             drawGC = XCreateGC(display, Nlm_currentXWindow, 0, NULL); 
  1385.             XSetFunction(display, drawGC, GXcopy); 
  1386.             XPutImage(display, pixmap, drawGC, ximage, 0,0, 0,0, width, height);
  1387.             XCopyArea(display, pixmap, Nlm_currentXWindow, drawGC, 0, 0, 
  1388.                     width, height, destrec.left - Nlm_XOffset, destrec.top - Nlm_YOffset);
  1389.             XFreeGC(display, drawGC); 
  1390.       XDestroyImage (ximage);
  1391.       XFreePixmap (display, pixmap);
  1392.             }
  1393.     }
  1394.  
  1395. #endif
  1396.  
  1397.     Nlm_MemFree( bits);
  1398.     Nlm_MemFree( kolorTab.ctTable);
  1399. }
  1400.  
  1401.  
  1402.  
  1403. void DDrawPict::drawPixmapOp9A( short version )
  1404. {
  1405.     word         mode;
  1406.     PIXMap     p;
  1407.     word         pixwidth;
  1408.     byte    * bits;
  1409.     //KolorTable kolorTab;
  1410.     Nlm_RecT     arec, sourcerec, destrec;
  1411.     ulong        unpackSize;
  1412.     
  1413.     skipbytes(4);
  1414.     p.pmVersion= getWord();    /* version */
  1415.     /* read_pixmap(&p, NULL); << not quite same for op9a */
  1416.     getRectAsis( &arec);
  1417.     p.Bounds.left= arec.left;
  1418.     p.Bounds.top= arec.top;
  1419.     p.Bounds.right= arec.right;
  1420.     p.Bounds.bottom= arec.bottom;
  1421.     /* p.pmVersion = getWord(); */
  1422.     p.packType = getWord();
  1423.     p.packSize = getLong();
  1424.     p.hRes = getLong();
  1425.     p.vRes = getLong();
  1426.     p.pixelType = getWord();
  1427.     p.pixelSize = getWord();
  1428.     p.pixelSize = getWord(); /* ?? is this right, two words ? */
  1429.     p.cmpCount = getWord();
  1430.     p.cmpSize = getWord();
  1431.     p.planeBytes = getLong();
  1432.     p.pmTable = getLong();
  1433.     p.pmReserved = getLong();
  1434.  
  1435.     pixwidth = p.Bounds.right - p.Bounds.left;
  1436.     /* kolorTab = read_colour_table(); << !! no color table in this op */
  1437.     
  1438.     getRectAsis( &sourcerec);
  1439.     getRectLocal( &destrec);
  1440.     mode = getWord();
  1441.  
  1442.     arec.left= p.Bounds.left;
  1443.     arec.top= p.Bounds.top;
  1444.     arec.right= p.Bounds.right;
  1445.     arec.bottom= p.Bounds.bottom;
  1446.     bits = unpackbits( &arec, 0, p.pixelSize, unpackSize);
  1447.     if (!bits) return;
  1448.  
  1449. #ifdef WIN_MAC
  1450.     {
  1451.   Nlm_RectTool   srcRect, dstRect;
  1452.   PixMap    srcBits;
  1453.   GrafPtr   port;
  1454.     CTabPtr        ctptr;
  1455.     
  1456.     Nlm_RecTToRectTool( &sourcerec, &srcRect);
  1457.     Nlm_RecTToRectTool( &destrec, &dstRect);
  1458.     ctptr= NULL; /* = (CTabPtr) &kolorTab; */
  1459.     
  1460.     /* ?? srcBits= *((PixMapPtr) &p); */
  1461.     srcBits.pmVersion= p.pmVersion;
  1462.     srcBits.packType= p.packType;
  1463.     srcBits.packSize= p.packSize;
  1464.     srcBits.hRes= p.hRes;
  1465.     srcBits.vRes= p.vRes;
  1466.     srcBits.pixelType= p.pixelType;
  1467.     srcBits.pixelSize= p.pixelSize;
  1468.     srcBits.cmpCount= p.cmpCount;
  1469.     srcBits.cmpSize= p.cmpSize;
  1470.     srcBits.planeBytes= p.planeBytes;
  1471.     srcBits.pmTable= &ctptr; /* p.pmTable;*/
  1472.     srcBits.pmReserved= p.pmReserved;
  1473.     
  1474.     srcBits.bounds.left= p.Bounds.left;
  1475.     srcBits.bounds.top = p.Bounds.top;
  1476.     srcBits.bounds.right= p.Bounds.right;
  1477.     srcBits.bounds.bottom= p.Bounds.bottom;
  1478.     srcBits.baseAddr = (Ptr) bits;
  1479.     /* srcBits.rowBytes = rowBytes;  */
  1480.     srcBits.rowBytes = (p.Bounds.right - p.Bounds.left - 1) / 8 + 1;
  1481.     
  1482.     GetPort (&port);
  1483.     CopyBits( (BitMap*) &srcBits, &port->portBits, &srcRect, &dstRect, mode, NULL);
  1484.     }
  1485. #endif
  1486. #ifdef WIN_MSWIN
  1487. #endif
  1488. #ifdef WIN_MOTIF
  1489. #endif
  1490.  
  1491.     Nlm_MemFree( bits);
  1492.     /* Nlm_MemFree( kolorTab.ctTable); */
  1493. }
  1494.  
  1495.  
  1496.  
  1497.  
  1498. void DDrawPict::drawBitmap(short version, short rowBytes, Nlm_Boolean isregion)
  1499. {
  1500.     Nlm_RecT bounds, sourcerec, destrec;
  1501.     word mode;
  1502.     byte *bits;
  1503.     ulong    unpackSize;
  1504.     
  1505.     getRectAsis(&bounds);
  1506.     getRectAsis(&sourcerec);
  1507.     getRectLocal( &destrec);
  1508.     mode = getWord();
  1509.     if (isregion) skipPolyOrRegion();
  1510.  
  1511.     bits = unpackbits( &bounds, rowBytes, 1, unpackSize);
  1512.     if (!bits) return;
  1513.     
  1514. #ifdef WIN_MAC
  1515.     {
  1516.   Nlm_RectTool   boundsRect, srcRect, dstRect;
  1517.   BitMap    srcBits;
  1518.   GrafPtr   port;
  1519.  
  1520.     Nlm_RecTToRectTool( &bounds, &boundsRect);
  1521.     Nlm_RecTToRectTool( &sourcerec, &srcRect);
  1522.     Nlm_RecTToRectTool( &destrec, &dstRect);
  1523.     srcBits.baseAddr = (Ptr) bits;
  1524.     srcBits.rowBytes = rowBytes;  
  1525.     srcBits.bounds = boundsRect;
  1526.     GetPort (&port);
  1527.     /* mode= srcCopy; /* testing... */
  1528.     CopyBits( &srcBits, &port->portBits, &srcRect, &dstRect, mode, NULL);
  1529.     }
  1530. #endif
  1531. #ifdef WIN_MSWIN
  1532.     /* Nlm_CopyBits( &destrec, bits); /* this is a hack -- should do directly */
  1533.   {
  1534.     HBITMAP       hBitmap, hOldBitmap;
  1535.     HDC           hMemoryDC;
  1536.     Nlm_Int4      wmode;
  1537.     Nlm_Int2      rop2, width, height, rows, depth;
  1538.  
  1539.         depth= 1; /* ?! check display depth */
  1540.         switch (mode) {
  1541.             /* translate apple to x modes */
  1542.             case 0: case 8: wmode = SRCCOPY; break;  /* srcCopy */
  1543.             case 1: case 9: wmode = SRCAND; break; /* srcOr */
  1544.             case 2: case 10: wmode = 0x00990066; break;   /* srcXor */
  1545.             case 3: case 11: wmode = MERGEPAINT; break;   /* srcBic */
  1546.             default:     wmode = SRCCOPY; /*WHITENESS;*/ break;
  1547.             }
  1548.  
  1549.     if (bits && Nlm_currentHDC) {
  1550.             width= destrec.right - destrec.left;
  1551.             height= destrec.bottom - destrec.top;
  1552.  
  1553.             hBitmap = CreateBitmap ( width, height, 1, depth, (LPSTR) bits);
  1554.             hMemoryDC = CreateCompatibleDC (Nlm_currentHDC);
  1555.             hOldBitmap = (HBITMAP) SelectObject (hMemoryDC, hBitmap);
  1556.       if (hOldBitmap != NULL) {
  1557.                 BitBlt (Nlm_currentHDC, destrec.left, destrec.top, width, height,
  1558.                                 hMemoryDC, 0, 0, wmode);
  1559.                 SelectObject (hMemoryDC, hOldBitmap);
  1560.                 }
  1561.             DeleteDC (hMemoryDC);
  1562.       DeleteObject (hBitmap);
  1563.             }
  1564.     }
  1565.  
  1566. #endif
  1567. #ifdef WIN_MOTIF
  1568.     /* Nlm_CopyBits( &destrec, bits); /* this is a hack -- should do directly */
  1569.  
  1570.     {
  1571.     short  width, height, xmode;
  1572.       Pixmap        pixmap;
  1573.  
  1574.         switch (mode) {
  1575.             /* translate apple to x modes */
  1576.             default: xmode= COPY_MODE;
  1577.             }
  1578.  
  1579.       width = destrec.right - destrec.left;
  1580.       height = destrec.bottom - destrec.top;
  1581.       pixmap = XCreateBitmapFromData (Nlm_currentXDisplay, Nlm_currentXWindow,
  1582.                                       (char *) bits, width, height);
  1583.       if (xmode != MERGE_MODE) {
  1584.         XCopyPlane (Nlm_currentXDisplay, pixmap, Nlm_currentXWindow,
  1585.                     Nlm_currentXGC, 0, 0, width, height,
  1586.                     destrec.left - Nlm_XOffset, destrec.top - Nlm_YOffset, 1);
  1587.           } 
  1588.             else {
  1589.         XSetClipOrigin (Nlm_currentXDisplay, Nlm_currentXGC,
  1590.                         destrec.left - Nlm_XOffset, destrec.top - Nlm_YOffset);
  1591.         XSetClipMask (Nlm_currentXDisplay, Nlm_currentXGC, pixmap);
  1592.         XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, GXcopy);
  1593.         XCopyPlane (Nlm_currentXDisplay, pixmap, Nlm_currentXWindow,
  1594.                     Nlm_currentXGC, 0, 0, width, height,
  1595.                     destrec.left - Nlm_XOffset, destrec.top - Nlm_YOffset, 1);
  1596.         XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, GXand);
  1597.         XSetClipOrigin (Nlm_currentXDisplay, Nlm_currentXGC, 0, 0);
  1598.         if (Nlm_clpRgn != NULL) {
  1599.           XSetRegion (Nlm_currentXDisplay, Nlm_currentXGC, (Nlm_RgnTool) Nlm_clpRgn);
  1600.         } else {
  1601.           XSetClipMask (Nlm_currentXDisplay, Nlm_currentXGC, None);
  1602.         }
  1603.       }
  1604.       XFreePixmap (Nlm_currentXDisplay, pixmap);
  1605.     }
  1606.  
  1607. #endif
  1608.  
  1609.     Nlm_MemFree( bits);
  1610. }
  1611.  
  1612.  
  1613.  
  1614.  
  1615. enum fontStyles {
  1616.     kFontBold = 1,
  1617.     kFontItalic = 2,
  1618.     kFontUline = 4,
  1619.     kFontOutline = 8,
  1620.     kFontShadow = 16,
  1621.     kFontCondense = 32,
  1622.     kFontExtend = 64
  1623.     };
  1624.  
  1625.  
  1626.  
  1627. void DDrawPict::InstallFont()
  1628. {
  1629.     fFont= Nlm_GetFont(fFontname, fFontsize, fFontstyle & kFontBold,
  1630.             fFontstyle & kFontItalic, fFontstyle & kFontUline, fFontfamily);
  1631.     Nlm_SelectFont( fFont);    
  1632.     fNeedInstallFont= FALSE;        
  1633. }
  1634.  
  1635. void DDrawPict::SetFont(word fontnum)
  1636. {
  1637.     short i;
  1638.     if (fontnum == fLastFontnum) {
  1639.         fFontname= fLastFontname;
  1640.         fNeedInstallFont= TRUE;    
  1641.         fLastFontnum = -1; /* clear it after 1 use ? */    
  1642.         return;
  1643.         }        
  1644.     else for ( i=0; QuickDrawFont[i].value>=0; i++) {
  1645.         if (fontnum == QuickDrawFont[i].value) {
  1646.             fFontname= QuickDrawFont[i].name;
  1647.             fNeedInstallFont= TRUE;        
  1648.             return;
  1649.             }
  1650.         }
  1651. }
  1652.  
  1653. void DDrawPict::SetFontStyle(byte fstyle)
  1654. {
  1655.     fFontstyle= fstyle;
  1656.     fNeedInstallFont= TRUE;        
  1657. }
  1658.  
  1659. void DDrawPict::SetFontSize(word fsize)
  1660. {
  1661.     fFontsize= fsize;
  1662.     fNeedInstallFont= TRUE;        
  1663. }
  1664.  
  1665.  
  1666.  
  1667.  
  1668. void DDrawPict::getAArc(Nlm_RectPtr arec, Nlm_PointPtr pt, Nlm_PointPtr pt1)   
  1669.     /* need some dang trigonometry here... */
  1670.     /* ?? just stuff a 45o angle for now ?? */
  1671.     short                arcStart, arcEnd;
  1672.     arcStart = getWord(); 
  1673.     arcEnd   = getWord();  
  1674.     pt->x = (arec->left + arec->right) >> 1; 
  1675.     pt->y = arec->top;  
  1676.     pt1->x= arec->right; 
  1677.     pt1->y= (arec->top + arec->bottom) >> 1; 
  1678. }
  1679.  
  1680. void DDrawPict::getAPoly(Nlm_RectPtr polybox, short* polycount, Nlm_PointPtr* thePoly) 
  1681.     short                 sizepoly,    npoly, ip;
  1682.     Nlm_PoinT          polypt;
  1683.     Nlm_PointPtr     apoly;
  1684.     
  1685.     apoly= *thePoly;
  1686.     sizepoly= getWord(); 
  1687.     getRectLocal( polybox); 
  1688.     npoly = (sizepoly - 10) >> 2;   
  1689.     if (!apoly) apoly= (Nlm_PoinT*) Nlm_MemNew( npoly * sizeof(Nlm_PoinT));  
  1690.     else apoly=  (Nlm_PoinT*) Nlm_MemMore( apoly, npoly * sizeof(Nlm_PoinT)); 
  1691.     if (apoly) for (ip= 0; ip<npoly; ip++) {  
  1692.         getPointLocal( &polypt);  
  1693.         apoly[ip]= polypt;  
  1694.         } 
  1695.     *thePoly= apoly;
  1696.     *polycount = npoly;
  1697.         /* debug TESTING... */
  1698.     /* *polycount= 0; */
  1699. }
  1700.      
  1701.      
  1702. void DDrawPict::getARgn(Nlm_RectPtr rgnbox, Nlm_RegioN* theRgn, Nlm_Boolean forclip)
  1703.   /* ! each win system has (?) own region format !! need to translate mac to others ! */
  1704.   /* just skip for now ! */
  1705.     short rgnsize;
  1706.     Nlm_RegioN    argn;
  1707.     
  1708.     argn= *theRgn;
  1709.     rgnsize= getWord(); 
  1710.     getRectLocal( rgnbox);
  1711.     
  1712.         /* this fix mainly for clip regions -- make sure it falls inside fPicRect */
  1713.     if (forclip) {
  1714.         if (rgnbox->left < fPicRect.left) rgnbox->left= fPicRect.left;
  1715.         if (rgnbox->top < fPicRect.top) rgnbox->top= fPicRect.top;
  1716.         if (rgnbox->right > fPicRect.right) rgnbox->right= fPicRect.right;
  1717.         if (rgnbox->bottom > fPicRect.bottom) rgnbox->bottom= fPicRect.bottom;
  1718.         }
  1719.     
  1720.     if (!argn) argn= Nlm_CreateRgn(); 
  1721.     else Nlm_ClearRgn( argn);  
  1722.     Nlm_LoadRectRgn( argn, rgnbox->left, rgnbox->top, rgnbox->right, rgnbox->bottom);  
  1723.     skipbytes( rgnsize - 10);  /* skip rgn data */
  1724.     *theRgn= argn;
  1725. }
  1726.  
  1727.  
  1728.  
  1729. void DDrawPict::getForeColor()
  1730. {
  1731.     switch (getLong()) {
  1732.         case 33: Nlm_Black(); break;
  1733.         case 30: Nlm_White(); break;
  1734.         case 205: Nlm_Red(); break;
  1735.         case 341: Nlm_Green(); break;
  1736.         case 409: Nlm_Blue(); break;
  1737.         case 273: Nlm_Cyan(); break;
  1738.         case 137: Nlm_Magenta(); break;
  1739.         case 69: Nlm_Yellow(); break;
  1740.         }
  1741. }
  1742.  
  1743.  
  1744. void DDrawPict::getBackColor()
  1745. {
  1746.     switch (getLong()) {
  1747.         case 33: Nlm_SelectBackColor(0,0,0); break;
  1748.         case 30: Nlm_SelectBackColor(255,255,255); break;
  1749.         case 205: Nlm_SelectBackColor(255,0,0); break;
  1750.         case 341: Nlm_SelectBackColor(0,255,0); break;
  1751.         case 409: Nlm_SelectBackColor(0,0,255); break;
  1752.         case 273: Nlm_SelectBackColor(0,255,255); break;
  1753.         case 137: Nlm_SelectBackColor(255,0,255); break;
  1754.         case 69: Nlm_SelectBackColor(255,255,0); break;
  1755.         }
  1756. }
  1757.  
  1758. void DDrawPict::getPenMode()
  1759. {
  1760.     switch (getWord()) {
  1761.         case 0: Nlm_CopyMode(); break;
  1762.         case 1: Nlm_MergeMode(); break;
  1763.         case 2: Nlm_InvertMode(); break;
  1764.         case 3: Nlm_EraseMode(); break;
  1765.         }
  1766. }
  1767.  
  1768.  
  1769. void DDrawPict::handleRectOpcode( word opcode)
  1770. {
  1771.     Nlm_PoinT        pt, pt1;
  1772.  
  1773.     getRectLocal( &fTheRect);
  1774.  
  1775. #if 0
  1776.     Nlm_MoveTo(fTheRect.left,fTheRect.top); /* ?? */
  1777. #endif
  1778.     switch (opcode) {
  1779.         case oframeRect:   if (fPenshown && fUnclipped) Nlm_FrameRect( &fTheRect); break;        
  1780.         case oeraseRect:   if (fUnclipped) Nlm_EraseRect( &fTheRect); break;        
  1781.         case opaintRect:   if (fUnclipped) Nlm_PaintRect( &fTheRect); break;        
  1782.         case oinvertRect:  if (fUnclipped) Nlm_InvertRect( &fTheRect); break;        
  1783.         case ofillRect:    /* setPattern(); Nlm_PaintRect( &fTheRect);*/  break;        
  1784.  
  1785.         case oframeRRect:   if (fPenshown && fUnclipped) Nlm_FrameRoundRect( &fTheRect, fOvSize.x, fOvSize.y); break;        
  1786.         case oeraseRRect:   if (fUnclipped) Nlm_EraseRoundRect( &fTheRect, fOvSize.x, fOvSize.y); break;        
  1787.         case opaintRRect:   if (fUnclipped) Nlm_PaintRoundRect( &fTheRect, fOvSize.x, fOvSize.y); break;        
  1788.         case oinvertRRect:  if (fUnclipped) Nlm_InvertRoundRect( &fTheRect, fOvSize.x, fOvSize.y); break;        
  1789.         case ofillRRect:    /* setPattern(); Nlm_PaintRoundRect( &fTheRect, fOvSize.x, fOvSize.y); */ break;        
  1790.  
  1791.         case oframeOval:   if (fPenshown && fUnclipped) Nlm_FrameOval( &fTheRect); break;        
  1792.         case oeraseOval:   if (fUnclipped) Nlm_EraseOval( &fTheRect); break;        
  1793.         case opaintOval:   if (fUnclipped) Nlm_PaintOval( &fTheRect); break;        
  1794.         case oinvertOval:  if (fUnclipped) Nlm_InvertOval( &fTheRect); break;        
  1795.         case ofillOval:    /* setPattern(); Nlm_PaintOval( &fTheRect); */ break;        
  1796.  
  1797.         case oframeArc:   getAArc(&fTheRect,&pt,&pt1); if (fPenshown && fUnclipped) Nlm_FrameArc( &fTheRect, pt, pt1); break;        
  1798.         case oeraseArc:   getAArc(&fTheRect,&pt,&pt1); if (fUnclipped) Nlm_EraseArc( &fTheRect, pt, pt1); break;        
  1799.         case opaintArc:   getAArc(&fTheRect,&pt,&pt1); if (fUnclipped) Nlm_PaintArc( &fTheRect, pt, pt1); break;        
  1800.         case oinvertArc:  getAArc(&fTheRect,&pt,&pt1); if (fUnclipped) Nlm_InvertArc( &fTheRect, pt, pt1); break;        
  1801.         case ofillArc:    getAArc(&fTheRect,&pt,&pt1); /* setPattern(); Nlm_PaintArc( &fTheRect, pt, pt1); */ break;        
  1802.     }
  1803. }
  1804.  
  1805. void DDrawPict::handleSameRectOpcode( word opcode)
  1806. {
  1807.     Nlm_PoinT        pt, pt1;
  1808.  
  1809.     switch (opcode) {
  1810.  
  1811.         case oframeSameRect:  if (fPenshown && fUnclipped) Nlm_FrameRect( &fTheRect); break;        
  1812.         case oeraseSameRect:  if (fUnclipped) Nlm_EraseRect( &fTheRect); break;        
  1813.         case opaintSameRect:  if (fUnclipped) Nlm_PaintRect( &fTheRect); break;        
  1814.         case oinvertSameRect: if (fUnclipped) Nlm_InvertRect( &fTheRect); break;        
  1815.         case ofillSameRect: /* setPattern(); Nlm_PaintRect( &fTheRect); */ break;        
  1816.  
  1817.         case oframeSameRRect:  if (fPenshown && fUnclipped) Nlm_FrameRoundRect( &fTheRect, fOvSize.x, fOvSize.y); break;        
  1818.         case oeraseSameRRect:  if (fUnclipped) Nlm_EraseRoundRect( &fTheRect, fOvSize.x, fOvSize.y); break;        
  1819.         case opaintSameRRect:  if (fUnclipped) Nlm_PaintRoundRect( &fTheRect, fOvSize.x, fOvSize.y); break;        
  1820.         case oinvertSameRRect: if (fUnclipped) Nlm_InvertRoundRect( &fTheRect, fOvSize.x, fOvSize.y); break;        
  1821.         case ofillSameRRect: /* setPattern(); Nlm_PaintRoundRect( &fTheRect, fOvSize.x, fOvSize.y); */  break;        
  1822.  
  1823.         case oframeSameOval:  if (fPenshown && fUnclipped) Nlm_FrameOval( &fTheRect); break;        
  1824.         case oeraseSameOval:  if (fUnclipped) Nlm_EraseOval( &fTheRect); break;        
  1825.         case opaintSameOval:  if (fUnclipped) Nlm_PaintOval( &fTheRect); break;        
  1826.         case oinvertSameOval: if (fUnclipped) Nlm_InvertOval( &fTheRect); break;        
  1827.         case ofillSameOval: /* setPattern(); Nlm_PaintOval( &fTheRect); */ break;        
  1828.  
  1829.         case oframeSameArc:  getAArc(&fTheRect,&pt,&pt1); if (fPenshown && fUnclipped) Nlm_FrameArc( &fTheRect, pt, pt1); break;        
  1830.         case oeraseSameArc:  getAArc(&fTheRect,&pt,&pt1); if (fUnclipped) Nlm_EraseArc( &fTheRect, pt, pt1); break;        
  1831.         case opaintSameArc:  getAArc(&fTheRect,&pt,&pt1); if (fUnclipped) Nlm_PaintArc( &fTheRect, pt, pt1); break;        
  1832.         case oinvertSameArc: getAArc(&fTheRect,&pt,&pt1); if (fUnclipped) Nlm_InvertArc( &fTheRect, pt, pt1); break;        
  1833.         case ofillSameArc: /* setPattern();  Nlm_PaintArc( &fTheRect, pt, pt1); */ break;        
  1834.  
  1835.         }
  1836. }
  1837.  
  1838.  
  1839.  
  1840. void* DDrawPict::IsPICT( void* pictdata, ulong datasize, Nlm_Boolean dontTestForHeader)
  1841. {    
  1842.     unsigned char        b;
  1843.     Nlm_RecT                aPicFrame;
  1844.     unsigned short    picversion, picSize;
  1845.     
  1846.     if (!pictdata) return NULL;
  1847. TestAgain:
  1848.     fPict=  (byte*) pictdata;
  1849.     picSize= getWord(); 
  1850.     getRectAsis( &aPicFrame);
  1851. #if ANOTHER_POSSIBLE_PICT_TEST
  1852.     if (picSize == 0) goto TestHead; 
  1853.     if (fPicRect.right - fPicRect.left <= 0 
  1854.      || fPicRect.bottom - fPicRect.top <= 0)  
  1855.         goto TestHead;  
  1856. #endif
  1857.  
  1858.     while ((b = getByte()) == 0) ;
  1859.     if (b != 0x011) goto TestHead; //return NULL;
  1860.     b = getByte();
  1861.     switch (b) {
  1862.         case 1:
  1863.             picversion= 1;
  1864.             return pictdata;
  1865.         case 2:
  1866.             picversion = 2;
  1867.             if (getByte() != 0xff) goto TestHead; //return NULL;
  1868.             return pictdata;
  1869.         default:
  1870.             goto TestHead; //return NULL;
  1871.         }
  1872.  
  1873. TestHead:
  1874.     if (dontTestForHeader || datasize<512) 
  1875.         return NULL;
  1876.     else { // skip possible 512-byte MacDraw header...
  1877.         pictdata = (Nlm_VoidPtr) ((unsigned long)pictdata + 512); 
  1878.         datasize -= 512;     
  1879.         dontTestForHeader= TRUE;
  1880.         goto TestAgain;
  1881.         }
  1882.  
  1883. }
  1884.  
  1885.  
  1886. void DDrawPict::GetFrame( Nlm_RectPtr frame, void* pictdata, ulong picsize, short kind)
  1887. {
  1888.     if (!pictdata || !frame) return;
  1889.     if (kind != kPictMac) return;
  1890.     fAlign= 0;
  1891.     fPicsize= picsize;
  1892.     fPict= (byte*) pictdata;
  1893.     short dummyPicSize= getWord();  
  1894.     getRectAsis( &fPicFrame);
  1895.     *frame= fPicFrame;
  1896. }
  1897.  
  1898.  
  1899. void DDrawPict::Draw( Nlm_RectPtr r, void* pictdata, ulong picsize, short kind)
  1900. {
  1901.     /* translator from Apple Quickdraw PICT data format to NCBIDraw methods */
  1902.     /* based on PICT I and II opcodes described in Inside Macintosh vol. V */
  1903.     /* some code from picttoppm.c, Copyright 1993 George Phillips <phillips@cs.ubc.ca> */
  1904.     
  1905.     enum { kMaxBuf = 257 };
  1906.  
  1907.     byte                b, *bp;
  1908.     word                 w, opcode;
  1909.     longword         curpat;
  1910.     short                i, dummyPicSize;
  1911.     Nlm_PoinT        pt, pt1;
  1912.     Nlm_PoinT        curpt; //-- track all moves w/ this?
  1913.     word                 red, green, blue;
  1914.     short                dh, dv;
  1915.     Nlm_Boolean            dorgn, done, clipWasSet, colored;
  1916.     char                *cp, buf[kMaxBuf];
  1917.     
  1918.     Nlm_PointPtr    apoly = NULL;
  1919.     Nlm_RecT        polybox;
  1920.     short                npoly;
  1921.  
  1922.     Nlm_RegioN    argn = NULL;
  1923.     Nlm_RecT        rgnbox;    
  1924.     
  1925.     
  1926.     if (!pictdata) return;
  1927.     if (kind != kPictMac) return;
  1928.     
  1929. #ifdef PLIST
  1930.     char fname[128];
  1931.     strcpy(fname,"work:+PicList-");
  1932.     if (gDoPlist) gPlist= fopen( fname, "w");
  1933. #endif
  1934.  
  1935.     fAlign= 0;
  1936.     fPicsize= picsize;
  1937.     fNeedInstallFont= true;
  1938.     fFontname = "Times"; 
  1939.     fFontfamily = "Roman";
  1940.     fFontsize = 12; 
  1941.     fFontstyle = 0;
  1942.     
  1943.     fPicRect=  *r;
  1944.     fPict= (byte*) pictdata;
  1945.     dummyPicSize= getWord();  
  1946.     getRectAsis( &fPicFrame);
  1947.     clipWasSet= FALSE; 
  1948.     fPenshown= TRUE;
  1949.     fUnclipped = TRUE;
  1950.     curpat= 0;
  1951.     colored= false;
  1952.     Nlm_MoveTo(fPicRect.left,fPicRect.top); /* ?? */
  1953. #ifdef PLIST
  1954.     if (gDoPlist) fprintf(gPlist, "\n global left,top: %d,%d\n",fPicRect.left,fPicRect.top);
  1955.     if (gDoPlist) fprintf(gPlist, " frame  left,top: %d,%d\n",fPicFrame.left,fPicFrame.top);
  1956. #endif
  1957.  
  1958.     while ((b = getByte()) == 0) ;
  1959.     if (b != 0x011) {
  1960.         bp=  (byte*) pictdata;
  1961.         cp= buf;
  1962.         for (i= 0; i<12; i++) { sprintf(cp, "%x%x ", *bp, *(bp+1)); cp += 5; bp += 2; }
  1963.         if (fVerbose) { Nlm_Message(MSG_OK,"drawpict: No version number %s", buf); fVerbose= false; }
  1964.         return;
  1965.         }
  1966.  
  1967.     b = getByte();
  1968.     switch (b) {
  1969.         case 1:
  1970.             fPictVersion= 1;
  1971.             break;
  1972.         case 2:
  1973.             fPictVersion = 2;
  1974.             if (getByte() != 0xff) {
  1975.                 if (fVerbose) { Nlm_Message(MSG_OK,"drawpict: can only do version 2, subcode 0xff"); fVerbose= false; }
  1976.                 return;
  1977.                 }
  1978.             break;
  1979.         default:
  1980.             fPictVersion= 0;
  1981.             bp= (byte*) pictdata;
  1982.             cp= buf;
  1983.             for (i= 0; i<12; i++) { sprintf(cp, "%x%x ", *bp, *(bp+1)); cp += 5; bp += 2; }
  1984.             if (fVerbose) { Nlm_Message(MSG_OK,"drawpict: unknown format %s", buf); fVerbose= false; }
  1985.             return;
  1986.         }
  1987.                 
  1988.     curpt.x= curpt.y= 0;
  1989.     done= false;
  1990.     while (true) { 
  1991.     
  1992.         if (done || (fPicsize && fAlign>=fPicsize)) {
  1993. #ifdef PLIST
  1994.             if (gDoPlist) fprintf(gPlist, "\n\n");
  1995.             fclose(gPlist);
  1996.             if (!done) Nlm_Beep();
  1997. #endif
  1998.             if (argn) argn= Nlm_DestroyRgn(argn);  
  1999.           if (apoly) Nlm_MemFree(apoly);  
  2000.           if (clipWasSet) Nlm_ResetClip();  
  2001.             /* ^^ Nlm_ResetClip IS BAD, can lead to messes, but NCBI Draw hasn't any GetClip() yet*/
  2002.             return;
  2003.             }
  2004.                 
  2005.         opcode= getOpcode();
  2006.  
  2007.         if (fNeedInstallFont && opcode != oTxFont && opcode != oTxFace 
  2008.             && opcode != oTxSize && opcode != oTxMode)  
  2009.             InstallFont();
  2010.             
  2011.         switch (opcode) {
  2012.         
  2013.             case oopEndPic: 
  2014.                 done= true;
  2015.               break; 
  2016.  
  2017.             case oNOP            : break; 
  2018.             case oVersion    : (void) getByte(); break;
  2019.             case oHeaderOp: skipbytes(24); break;
  2020.             
  2021.             case oClip        : 
  2022.                 /* usually 1st pict opcode after header is clip to fPicRect */
  2023.                 /* BUT some picts, a few icons, have this clip offset outside of true drawing rgn !! */
  2024.                 /* whose bug is this */
  2025.                 getARgn(&rgnbox, &argn, TRUE);
  2026. #if 1
  2027.                 //fUnclipped= ( ! Nlm_EmptyRect( &rgnbox));
  2028.                 fUnclipped = (rgnbox.left < rgnbox.right && rgnbox.top < rgnbox.bottom);
  2029. #else
  2030.                 Nlm_ClipRgn(argn); // << leaving unclipped for debugging 
  2031.                 clipWasSet= TRUE; 
  2032. #endif
  2033.                 break;  
  2034.                 
  2035.             case oOvSize    : getPointAsis( &fOvSize);  break;
  2036.             case oOrigin    :     // oOrigin data is dh:word, dv:word
  2037.                 {
  2038.                 short  dh, dv;
  2039.                 dh= (signed short) getWord();
  2040.                 dv= (signed short) getWord();
  2041.                 Nlm_OffsetRect( &fPicFrame, dh, dv);
  2042.                     // we also must move current point...
  2043.                 curpt.x -= dh;
  2044.                 curpt.y -= dv;
  2045.                 Nlm_GetPen( &pt); // bad for X,?MWin?
  2046.                 pt.x -= dh; // this one is bad !? mirror of 
  2047.                 pt.y -= dv;
  2048.                 Nlm_MoveTo( pt.x, pt.y); 
  2049. #ifdef PLIST
  2050.                 if (gDoPlist) {
  2051.                     fprintf( gPlist, " dh,v: %d,%d  or.left,top: %d,%d, pt.x,y %d,%d", 
  2052.                             dh,dv, fPicFrame.left, fPicFrame.top, pt.x, pt.y); 
  2053.                     }
  2054. #endif
  2055.                 
  2056.                 }
  2057.                 break;
  2058.                 
  2059.             case oChExtra    :    (void) getWord(); break;
  2060.             case oPnLocHFrac: (void) getWord(); break;
  2061.     
  2062.             case oBkPat        : skipbytes(8); break;
  2063.             case oFillPat    : skipbytes(8); break;
  2064.             case oPnPat        : 
  2065. #if 1
  2066.                 for (i=0, curpat=0; i<8; i++) {
  2067.                     curpat <<= 1;
  2068.                     curpat += getByte();
  2069.                     }
  2070. #else
  2071.                 skipbytes(8); /* patterns COULD be supported in NCBI draw w/ some extra code */
  2072. #endif
  2073.                 break;
  2074.             case oBkPixPat    : read_pattern(); break;
  2075.             case oPnPixPat    : read_pattern(); break;
  2076.             case oFillPixPat: read_pattern(); break;
  2077.  
  2078.             case oHiliteMode    : break;
  2079.             case oHiliteColor    : skipbytes(6); break;
  2080.             case oDefHilite        : break;
  2081.             case oOpColor            : getRGBKolor( &fOpcolor); break; 
  2082.             case oShortComment: skipbytes(2); break;
  2083.             case oLongComment : 
  2084.                 w= getWord(); /* kind */
  2085.                  w= getWord(); /* size */
  2086.                  skipbytes(w); 
  2087.                  break;
  2088.  
  2089.  
  2090.             case oPackBitsRgn:
  2091.             case oBitsRgn:
  2092.                 dorgn= TRUE;
  2093.                 goto readbits;
  2094.             case oPackBitsRect:
  2095.             case oBitsRect:    
  2096.                 dorgn= FALSE;
  2097.             readbits:
  2098.                 {
  2099.                 word rowbytes= getWord();
  2100.                 if (rowbytes & 0x8000)  
  2101.                     drawPixmap( fPictVersion, rowbytes, dorgn);
  2102.                 else  
  2103.                     drawBitmap( fPictVersion, rowbytes, dorgn);
  2104.                 }
  2105.                 break;
  2106.             case oOpcode9A: drawPixmapOp9A( fPictVersion); break;            
  2107.                 
  2108.                             
  2109.             case oTxFont    : w= getWord(); SetFont(w); break;
  2110.             case oTxFace    : b= getByte(); SetFontStyle(b); break;
  2111.             case oTxSize    : w= getWord(); SetFontSize(w); break;
  2112.             case oTxRatio    : skipbytes(8); break;    
  2113.             case oSpExtra    : skipbytes(4); break;
  2114.             case oTxMode    :    getPenMode();    break;
  2115.                     
  2116.             case oFontName: /* was res2c */
  2117.                 w= getWord();
  2118.                 if (w>3) {
  2119.                     fLastFontnum= getWord();
  2120.                     w -= 2;
  2121.                     b= getByte();
  2122.                     w -= 1 + b;
  2123.                     getbytes( fLastFontname, b); 
  2124.                     fLastFontname[b]= 0;
  2125.                     }
  2126.                 if (w>0) skipbytes(w);                
  2127.                  break;
  2128.             
  2129.             
  2130.             case oPnSize: 
  2131.                 getPointAsis( &pt); 
  2132.                  Nlm_WidePen(pt.x); 
  2133.                  fPenshown= (pt.x != 0);
  2134.                 break;
  2135.             case oPnMode: 
  2136.                 getPenMode();
  2137.                 break;
  2138.             
  2139.                 /* these are PICT 1 oldstyle colors, not translatable to RGB values !! */
  2140.             case oFgColor: 
  2141.                 getForeColor();
  2142.                 colored= true; 
  2143.                 break;
  2144.  
  2145.             case oBkColor: 
  2146.                 getBackColor();
  2147.                 break;
  2148.                 
  2149.             case oRGBFgCol:
  2150.                 /* getRGBKolor( &aColor); */
  2151.                 red= getWord() >> 8; 
  2152.                 green= getWord() >> 8; 
  2153.                 blue= getWord() >> 8;
  2154.                 Nlm_SelectColor(red,green,blue);
  2155.                 colored= true; 
  2156.                 break;
  2157.             case oRGBBkCol:  
  2158.                 red= getWord() >> 8; 
  2159.                 green= getWord() >> 8; 
  2160.                 blue= getWord() >> 8;
  2161.                 Nlm_SelectBackColor(red,green,blue);
  2162.                 break;
  2163.  
  2164.             case oLine:
  2165.                 getPointLocal( &pt); 
  2166.                 getPointLocal( &pt1);
  2167.                 if (fPenshown && fUnclipped) Nlm_DrawLine( pt, pt1);
  2168.                 else Nlm_MoveTo( pt1.x, pt1.y); 
  2169.                 curpt= pt1;
  2170.                 break;
  2171.             case oLineFrom:    
  2172.                 getPointLocal( &pt); 
  2173.                 if (fPenshown && fUnclipped) Nlm_LineTo(pt.x, pt.y);
  2174.                 else Nlm_MoveTo( pt.x, pt.y); 
  2175.                 curpt= pt;
  2176.                 break;
  2177.                 
  2178.             case oShortLine: 
  2179.                 getPointLocal( &pt); 
  2180.                 dh= (signed char) getByte();
  2181.                 dv= (signed char) getByte();
  2182.                 pt1.x = pt.x + dh;
  2183.                 pt1.y = pt.y + dv;
  2184. #if 0
  2185.                 if (fPenshown && fUnclipped) {
  2186.                     Nlm_GetPen( &pt0);
  2187.                     Nlm_DrawLine( pt, pt1);
  2188.                     Nlm_MoveTo( pt0.x, pt0.y); 
  2189.                     }
  2190. #else
  2191.                 if (fPenshown && fUnclipped) Nlm_DrawLine( pt, pt1);
  2192.                 else Nlm_MoveTo( pt1.x, pt1.y); 
  2193.                 //curpt= pt1;                  // !! can't move here or DH/DVText is screwed !!!!
  2194. #endif
  2195.                 break;
  2196.                 
  2197.             case oShortLineFrom:
  2198.                 dh= (signed char) getByte();
  2199.                 dv= (signed char) getByte();
  2200.                 Nlm_GetPen( &pt);  // bad for X,?MWin?
  2201.                 pt1.x= pt.x + dh;
  2202.                 pt1.y= pt.y + dv;
  2203. #if 0
  2204.                 if (fPenshown && fUnclipped) {
  2205.                     Nlm_LineTo( pt1.x, pt1.y);
  2206.                     Nlm_MoveTo( pt.x, pt.y); 
  2207.                     }
  2208. #else
  2209.                 if (fPenshown && fUnclipped) Nlm_LineTo(pt1.x, pt1.y);
  2210.                 else Nlm_MoveTo( pt1.x, pt1.y); 
  2211.                 //curpt= pt1;// !! can't move here or DH/DVText is screwed !!!!
  2212. #endif
  2213.                 break;
  2214.  
  2215.                  
  2216.             case or2e_mov:  /* was r2e -- ?? a moveto??  */
  2217.                 w= getWord();
  2218.                 if (w>0) skipbytes(w);
  2219.                 break;
  2220.  
  2221.             case oLongText:
  2222.                 getPointLocal( &pt); 
  2223.                 curpt= pt;
  2224.                 goto caseDrawString;                
  2225.             case oDHDVText:
  2226.             case oDVText:
  2227.             case oDHText:
  2228. #if 1
  2229.                 pt= curpt;
  2230. #else
  2231.                 Nlm_GetPen( &pt);
  2232. #endif
  2233.                 dh= getByte();
  2234.                 if (opcode == oDHDVText){
  2235.                     pt.x += dh;
  2236.                     dv= getByte();
  2237.                     pt.y += dv;
  2238.                     }
  2239.                 else if (opcode == oDVText) pt.y += dh;
  2240.                 else pt.x += dh;
  2241.             caseDrawString:
  2242.                 Nlm_MoveTo( pt.x, pt.y);
  2243.                 b= getByte();
  2244.                 getbytes( buf, b); 
  2245.                 buf[b]= 0;
  2246. #ifdef PLIST
  2247.                 if (gDoPlist) fprintf( gPlist, " x,y: %d,%d",pt.x, pt.y); 
  2248.                 if (gDoPlist) fprintf( gPlist, " '%s'",buf); 
  2249. #endif
  2250.                 if (fUnclipped) Nlm_PaintString( buf);
  2251.                 Nlm_MoveTo( pt.x, pt.y); // Nlm_PaintString moves to pt.x + stringlen(buf)
  2252.                 curpt= pt;
  2253.                 break;    
  2254.     
  2255.             
  2256.             /* fill...() are disabled until we get setPattern working... */
  2257.             case opaintRect:      
  2258.                 if (!fPenshown && !colored && curpat == 0) opcode= oeraseRect; // quick hack to fix null patterns
  2259.             case oframeRect:      
  2260.             case oeraseRect:       
  2261.             case oinvertRect:     
  2262.             case ofillRect:      
  2263.                     handleRectOpcode( opcode);
  2264.                     break;
  2265.                 
  2266.             case opaintRRect:      
  2267.                 if (!fPenshown && !colored && curpat == 0) opcode= oeraseRRect; // quick hack to fix null patterns
  2268.             case oframeRRect:  
  2269.             case oeraseRRect:      
  2270.             case oinvertRRect: 
  2271.             case ofillRRect:  
  2272.                     handleRectOpcode( opcode);
  2273.                     break;
  2274.  
  2275.             case opaintOval:  
  2276.                 if (!fPenshown && !colored && curpat == 0) opcode= oeraseOval; // quick hack to fix null patterns
  2277.             case oframeOval:      
  2278.             case oeraseOval: 
  2279.             case oinvertOval:     
  2280.             case ofillOval:  
  2281.                     handleRectOpcode( opcode);
  2282.                     break;
  2283.  
  2284.             case opaintArc:      
  2285.                 if (!fPenshown && !colored && curpat == 0) opcode= oeraseArc; // quick hack to fix null patterns
  2286.             case oframeArc:           
  2287.             case oeraseArc:          
  2288.             case oinvertArc:      
  2289.             case ofillArc:  
  2290.                     handleRectOpcode( opcode);
  2291.                     break;
  2292.  
  2293.  
  2294.             case opaintSameRect:      
  2295.                 if (!fPenshown && !colored && curpat == 0) opcode= oeraseSameRect; // quick hack to fix null patterns
  2296.             case oframeSameRect:      
  2297.             case oeraseSameRect:       
  2298.             case oinvertSameRect:      
  2299.             case ofillSameRect: 
  2300.                     handleSameRectOpcode(opcode);
  2301.                     break;
  2302.  
  2303.             case opaintSameRRect:      
  2304.                 if (!fPenshown && !colored && curpat == 0) opcode= oeraseSameRRect; // quick hack to fix null patterns
  2305.             case oframeSameRRect:  
  2306.             case oeraseSameRRect:   
  2307.             case oinvertSameRRect:      
  2308.             case ofillSameRRect:      
  2309.                     handleSameRectOpcode(opcode);
  2310.                     break;
  2311.  
  2312.             case opaintSameOval:      
  2313.                 if (!fPenshown && !colored && curpat == 0) opcode= oeraseSameOval; // quick hack to fix null patterns
  2314.             case oframeSameOval:      
  2315.             case oeraseSameOval:      
  2316.             case oinvertSameOval:        
  2317.             case ofillSameOval:  
  2318.                     handleSameRectOpcode(opcode);
  2319.                     break;
  2320.  
  2321.             case opaintSameArc:      
  2322.                 if (!fPenshown && !colored && curpat == 0) opcode= oeraseSameArc; // quick hack to fix null patterns
  2323.             case oframeSameArc:     
  2324.             case oeraseSameArc:      
  2325.             case oinvertSameArc:          
  2326.             case ofillSameArc: 
  2327.                     handleSameRectOpcode(opcode);
  2328.                     break;
  2329.  
  2330.             case oframePoly:  getAPoly(&polybox, &npoly, &apoly); if (fPenshown && fUnclipped) Nlm_FramePoly( npoly, apoly); break;        
  2331.             case oerasePoly:  getAPoly(&polybox, &npoly, &apoly); if (fUnclipped) Nlm_ErasePoly( npoly, apoly); break;        
  2332.             case opaintPoly:  getAPoly(&polybox, &npoly, &apoly); 
  2333.                     if (fUnclipped) {
  2334.                          if (!fPenshown && !colored && curpat == 0) Nlm_ErasePoly( npoly, apoly);
  2335.                         else Nlm_PaintPoly( npoly, apoly); 
  2336.                         }
  2337.                     break;        
  2338.             case oinvertPoly: getAPoly(&polybox, &npoly, &apoly); if (fUnclipped) Nlm_InvertPoly( npoly, apoly); break;        
  2339.             case ofillPoly:   getAPoly(&polybox, &npoly, &apoly); /* setPattern();  Nlm_PaintPoly( npoly, apoly); */ break;        
  2340.  
  2341.             case oframeSamePoly:  if (fPenshown && fUnclipped) Nlm_FramePoly( npoly, apoly); break;        
  2342.             case oeraseSamePoly:  if (fUnclipped) Nlm_ErasePoly( npoly, apoly); break;        
  2343.             case opaintSamePoly:  
  2344.                     if (fUnclipped) {
  2345.                         if (!fPenshown && !colored && curpat == 0) Nlm_ErasePoly( npoly, apoly);
  2346.                         else Nlm_PaintPoly( npoly, apoly); 
  2347.                         }
  2348.                      break;    
  2349.             case oinvertSamePoly: if (fUnclipped) Nlm_InvertPoly( npoly, apoly); break;        
  2350.             case ofillSamePoly: /* setPattern();  Nlm_PaintPoly( npoly, apoly); */  break;        
  2351.  
  2352.             case oframeRgn:  getARgn(&rgnbox, &argn, FALSE); if (fPenshown && fUnclipped) Nlm_FrameRgn( argn); break;        
  2353.             case oeraseRgn:  getARgn(&rgnbox, &argn, FALSE); if (fUnclipped) Nlm_EraseRgn( argn); break;        
  2354.             case opaintRgn:  getARgn(&rgnbox, &argn, FALSE); 
  2355.                 if (fUnclipped) {
  2356.                     if (!fPenshown && !colored && curpat == 0) Nlm_EraseRgn(argn);
  2357.                     else Nlm_PaintRgn( argn);
  2358.                     }
  2359.                 break;        
  2360.             case oinvertRgn: getARgn(&rgnbox, &argn, FALSE); if (fUnclipped) Nlm_InvertRgn( argn); break;        
  2361.             case ofillRgn:   getARgn(&rgnbox, &argn, FALSE); /* setPattern(); Nlm_PaintRgn( argn); */ break;        
  2362.  
  2363.             case oframeSameRgn:  if (fPenshown && fUnclipped) Nlm_FrameRgn( argn); break;        
  2364.             case oeraseSameRgn:  if (fUnclipped) Nlm_EraseRgn( argn); break;        
  2365.             case opaintSameRgn:  
  2366.                 if (fUnclipped) {
  2367.                     if (!fPenshown && !colored && curpat == 0) Nlm_EraseRgn(argn);
  2368.                     else Nlm_PaintRgn( argn);
  2369.                     }
  2370.                 break;        
  2371.             case oinvertSameRgn: if (fUnclipped) Nlm_InvertRgn( argn); break;        
  2372.             case ofillSameRgn: /* setPattern(); Nlm_PaintRgn( argn); */  break;        
  2373.  
  2374.             case r17: case r18: case r19: break;                
  2375.             case r24: case r25: case r26: case r27:        skipbytes( getWord()); break;
  2376.             case r2d: case r2f: skipbytes( getWord()); break;
  2377.             case r35: case r36: case r37: skipbytes( 8); break;
  2378.             case r3d: case r3e: case r3f: break;
  2379.             case r45: case r46: case r47: skipbytes( 8); break;
  2380.             case r4d: case r4e: case r4f: break;
  2381.             case r55: case r56: case r57: skipbytes( 8); break;
  2382.             case r5d: case r5e: case r5f: break;
  2383.             case r65: case r66: case r67: skipbytes( 12); break;
  2384.             case r6d: case r6e: case r6f: skipbytes( 4); break;
  2385.             case r75: case r76: case r77: skipPolyOrRegion(); break;
  2386.             case r7d: case r7e: case r7f: break;
  2387.             case r85: case r86: case r87: skipPolyOrRegion(); break;
  2388.             case r8d: case r8e: case r8f: break;
  2389.             case r92: case r93: case r94: 
  2390.             case r95: case r96: case r97:    skipbytes( getWord()); break;
  2391.             case r9b: case r9c: case r9d: case r9e: case r9f:    skipbytes( getWord()); break;
  2392.                 
  2393.             default : {
  2394.                 if (opcode >= 0xa2 && opcode <= 0xaf) skipbytes( getWord());
  2395.                 else if (opcode >= 0x0b0 && opcode <= 0x0cf) ; 
  2396.                 else if (opcode >= 0x0d0 && opcode <= 0x0fe)     skipbytes( getLong());
  2397.                 else if (opcode >= 0x100 && opcode <= 0x7fff) skipbytes( (opcode >> 7) & 255);
  2398.                 else if (opcode >= 0x8000 && opcode <= 0x80ff) ; 
  2399.                  else if (opcode >= 0x8100 && opcode <= 0xffff) skipbytes( getLong());
  2400.                 else 
  2401.                     Nlm_Message(MSG_FATAL,"drawpict: don't know opcode %x", opcode);
  2402.                 }
  2403.  
  2404.             }
  2405.         }  
  2406.         
  2407. }
  2408.  
  2409.  
  2410.